-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SSR and Serverless experiments [DO NOT MERGE] #812
Conversation
return '<h1>Content goes here</h1>'; | ||
} | ||
|
||
async function getMetadata() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One good point that was brought up during the call was that we could this getMetadata
function to provide more hints to Greenwood such that even if routes exist in the project, but the user still wants to statically export them (so no server at runtime) we could definitely handle this:
async function getMetadata() {
return {
staticExport: true
}
}
This would provide NextJS like behavior in that you can author purely dynamic content at build time but still reuse your templates / components / styles, and get a completely static artifact just as if it was in the pages/ directory. 📦 🙌
Interesting thread that could help us with designing an entry file that is both |
if (command === 'serverless') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this would be helpful for detecting if run from JS or run from the CLI; import.meta.main
- https://github.com/nodejs/modules/issues/274#issuecomment-1302971322
Serverless support released as part of v0.29.0! 🚀 |
Overview
Opening this for demonstration and discussion purposes and to flesh out ideas and architecture for implementing server side and serverless capabilities for Greenwood. The goal is to see what an implementation might look like, how it plays together with other parts of the system, and what implications there are that should be accounted for ahead of actually intending to submit a PR.
SSR
I think what's really cool about the possibilities here is how seamless it would be to run a hybrid application, such that you can have a set of static and dynamic pages and routes that can all share the same static resources, yet still feel like one app.
In this way
I tried to demonstrate that here in this PR with the "Artists" page, though obviously this will not work on Netlify, but you can try it locally!
Testing
To run this branch on a server
git clone
the repo and checkout this branchyarn install
yarn serve
From your public IP (make sure to open up port
8080
through your SGs, etc)http://x.x.x.x:8080/
http://x.x.x.x:8080/artists
Live Demos (make sure I've started the server first!)
Caveats
prerender
config setting tofalse
prerender
tofalse
- see settingprerender: false
andoptimization: inline
leads to broken and missing styles #810Serverless
Since there are typically size constraints related to running serverless, for this reason, to limit size, it may be advisable to:
Testing
npx @greenwood/init --install
cd
into that directory and delete puppeteer from node_modulesOr you can clone this reference repo.
Workflow
run()
function in index.js and then runnode ./index.js
yarn dist
Live Demos
Caveats
Notes / Takeaways
mode
config option, and remove it entirely? I would like to implement "progressive configuration" such that if we see a user has pages and / or routes, or just an index.html, we can handle that without needing to have it configured by the user. I think this is because now we really have a hybrid situation and it should be easy for users to static and add / go dynamic, would be sweet. Instead, we turnmpa
mode into astaticRouter
config such that if users want this static route (since it's not designed for SPA) they can use that instead.prerender
off by default. The website builds sooooo much faster without it, so it is definitely probably better for us to not force that long time as default, especially if you really just want a static site.Open Items
/artist/:id