Node.js standalone mode + support for astro preview#5056
Conversation
🦋 Changeset detectedLatest commit: e7a9bd9 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
!preview |
|
Invalid comment format. Expected: "!preview " |
|
!preview node-standalone |
|
|
Released a snapshot for this which can be installed with: npm install astro@next--node-standalone @astrojs/node@next--node-standalone |
FredKSchott
left a comment
There was a problem hiding this comment.
LGTM! Flagging @withastro/maintainers-docs for a review of the types additions.
|
|
||
| export default defineConfig({ | ||
| output: 'server', | ||
| build: { |
There was a problem hiding this comment.
nice! This makes a lot of sense!
|
|
||
| See the @astrojs/node documentation to learn all of the options available in standalone mode. | ||
|
|
||
| ## Breaking change |
There was a problem hiding this comment.
thinking more about this, if you default to middleware and make this option required, do you still need the major version?
There was a problem hiding this comment.
It wouldn't be required if it had a default, no?
We could default to middleware. My thought was that these two modes are pretty significantly different and it didn't feel right to "prefer" one over the other. Kind of like Vercel serverless vs edge, just completely different things.
As far as semver, given that this is an integration I didn't think it mattered as much to do a semver major change.
But I don't feel too strongly on either of these things.
There was a problem hiding this comment.
yea, agreed that because its an integration this doesn't matter as much / I'm okay with the plan for a major. And I agree it makes more sense as required, or as defaulting to standalone. Defaulting to middleware is probably the least natural of the 3...
There was a problem hiding this comment.
Ok, I think we should do a major in that case and require the option. We can track usage in the future and if standalone is overwhelming (and once it becomes more stable) we can make it the default if we want to.
sarah11918
left a comment
There was a problem hiding this comment.
Just left a few text suggestions to consider, and one other thing you might want to consider is a link or note to these new server configs around line 400ish from outputDir, to make it known that they exist in SSR mode.
| * This entrypoint is usually dependent on which host you are deploying to and | ||
| * will be set by your adapter for you. | ||
| * | ||
| * Note that it is recommended that this file ends with `.mjs` so that the runtime |
There was a problem hiding this comment.
| * Note that it is recommended that this file ends with `.mjs` so that the runtime | |
| * Note that it is recommended that this file ends with `.mjs` so that the runtime |
Just checking this is intentional, because I think I've only ever heard "runtime" as an adjective "runtime environment, runtime system, runtime library". If this is a noun, then it's fine!
There was a problem hiding this comment.
I've definitely heard it used as a noun. In fact, nodejs.org's <meta description> tag uses it as one! view-source:https://nodejs.org/en/
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
tony-sull
left a comment
There was a problem hiding this comment.
Nice! I've been missing astro preview support for Netlify's CLI, great to see this new API will open that door 👍
Change looks good to me, just added one note in the image integration to make sure this won't break WASM support
| if(needsBuildConfig) { | ||
| _buildConfig = buildConfig; | ||
| } |
There was a problem hiding this comment.
_buildConfig.server is used in the astro:build:ssr step below, does it need to be updated to make sure wasm files are copied to the preview output directory?
There was a problem hiding this comment.
So, this line exists for backwards compatibility. If you are using Astro < 1.5.0 then this line will get _buildConfig from the 'astro:build:start' hook. If you are using Astro >= 1.5.0 then it will get it from the 'astro:config:done' hook here: https://github.com/withastro/astro/pull/5056/files#diff-0000f87084d8080bf428d6b3b7dc84cda4f01465d9a3e95c75bbc38b8129e1e5R99
In the future when we do a new major (or minor in the case of astro/image) we can get rid of this code and only support users of Astro >= 1.5.0
|
Hello @matthewp, Node.js standalone mode, css resources unable to load.
|
Build did not work on latest version of "create astro".
```
"dependencies": {
"astro": "^2.0.2"
},
"devDependencies": {
"@matthewp/astro-fastify": "^2.0.3"
}
```
Issue origin: withastro/astro#5056
* wip * Deprecate buildConfig and move to config.build * Implement the standalone server * Stay backwards compat * Add changesets * correctly merge URLs * Get config earlier * update node tests * Return the preview server * update remaining tests * swap usage and config ordering * Update packages/astro/src/@types/astro.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/metal-pumas-walk.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/metal-pumas-walk.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/stupid-points-refuse.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/stupid-points-refuse.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Link to build.server config Co-authored-by: Fred K. Schott <fkschott@gmail.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
* wip * Deprecate buildConfig and move to config.build * Implement the standalone server * Stay backwards compat * Add changesets * correctly merge URLs * Get config earlier * update node tests * Return the preview server * update remaining tests * swap usage and config ordering * Update packages/astro/src/@types/astro.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/metal-pumas-walk.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/metal-pumas-walk.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/stupid-points-refuse.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/stupid-points-refuse.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Link to build.server config Co-authored-by: Fred K. Schott <fkschott@gmail.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
* wip * Deprecate buildConfig and move to config.build * Implement the standalone server * Stay backwards compat * Add changesets * correctly merge URLs * Get config earlier * update node tests * Return the preview server * update remaining tests * swap usage and config ordering * Update packages/astro/src/@types/astro.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/metal-pumas-walk.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/metal-pumas-walk.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/stupid-points-refuse.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/stupid-points-refuse.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Link to build.server config Co-authored-by: Fred K. Schott <fkschott@gmail.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
* wip * Deprecate buildConfig and move to config.build * Implement the standalone server * Stay backwards compat * Add changesets * correctly merge URLs * Get config earlier * update node tests * Return the preview server * update remaining tests * swap usage and config ordering * Update packages/astro/src/@types/astro.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/metal-pumas-walk.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/metal-pumas-walk.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/stupid-points-refuse.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/stupid-points-refuse.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Link to build.server config Co-authored-by: Fred K. Schott <fkschott@gmail.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
* wip * Deprecate buildConfig and move to config.build * Implement the standalone server * Stay backwards compat * Add changesets * correctly merge URLs * Get config earlier * update node tests * Return the preview server * update remaining tests * swap usage and config ordering * Update packages/astro/src/@types/astro.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/metal-pumas-walk.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/metal-pumas-walk.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/stupid-points-refuse.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/stupid-points-refuse.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Link to build.server config Co-authored-by: Fred K. Schott <fkschott@gmail.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>


Changes
previewEntrypointAPI that adapters can support to enableastro preview.{ mode: 'standalone' }option for the @astrojs/node adapter.buildConfigoption inastro:build:startin favor of moving those same options toconfig.build.Testing
examples/ssrexample.Docs