Skip to content

Commit

Permalink
Node.js standalone mode + support for astro preview (#5056)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Update .changeset/metal-pumas-walk.md

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update .changeset/metal-pumas-walk.md

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update .changeset/stupid-points-refuse.md

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update .changeset/stupid-points-refuse.md

Co-authored-by: Sarah Rainsberger <[email protected]>

* Link to build.server config

Co-authored-by: Fred K. Schott <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
  • Loading branch information
3 people authored Oct 12, 2022
1 parent 3de9853 commit 8debb79
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
28 changes: 21 additions & 7 deletions packages/integrations/vercel/src/edge/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,35 @@ export default function vercelEdge(): AstroIntegration {
let _config: AstroConfig;
let functionFolder: URL;
let serverEntry: string;
let needsBuildConfig = false;

return {
name: PACKAGE_NAME,
hooks: {
'astro:config:setup': ({ config }) => {
config.outDir = getVercelOutput(config.root);
'astro:config:setup': ({ config, updateConfig }) => {
needsBuildConfig = !config.build.client;
const outDir = getVercelOutput(config.root);
updateConfig({
outDir,
build: {
serverEntry: 'entry.mjs',
client: new URL('./static/', outDir),
server: new URL('./functions/render.func/', config.outDir),
}
});
},
'astro:config:done': ({ setAdapter, config }) => {
setAdapter(getAdapter());
_config = config;
serverEntry = config.build.serverEntry;
functionFolder = config.build.server;
},
'astro:build:start': ({ buildConfig }) => {
if(needsBuildConfig) {
buildConfig.client = new URL('./static/', _config.outDir);
serverEntry = buildConfig.serverEntry = 'entry.mjs';
functionFolder = buildConfig.server = new URL('./functions/render.func/', _config.outDir);
}
},
'astro:build:setup': ({ vite, target }) => {
if (target === 'server') {
Expand All @@ -49,11 +68,6 @@ export default function vercelEdge(): AstroIntegration {
};
}
},
'astro:build:start': async ({ buildConfig }) => {
buildConfig.serverEntry = serverEntry = 'entry.mjs';
buildConfig.client = new URL('./static/', _config.outDir);
buildConfig.server = functionFolder = new URL('./functions/render.func/', _config.outDir);
},
'astro:build:done': async ({ routes }) => {
// Edge function config
// https://vercel.com/docs/build-output-api/v3#vercel-primitives/edge-functions/configuration
Expand Down
28 changes: 21 additions & 7 deletions packages/integrations/vercel/src/serverless/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,29 @@ export default function vercelEdge(): AstroIntegration {
let buildTempFolder: URL;
let functionFolder: URL;
let serverEntry: string;
let needsBuildConfig = false;

return {
name: PACKAGE_NAME,
hooks: {
'astro:config:setup': ({ config }) => {
config.outDir = getVercelOutput(config.root);
'astro:config:setup': ({ config, updateConfig }) => {
needsBuildConfig = !config.build.client;
const outDir = getVercelOutput(config.root);
updateConfig({
outDir,
build: {
serverEntry: 'entry.js',
client: new URL('./static/', outDir),
server: new URL('./dist/', config.root),
}
});
},
'astro:config:done': ({ setAdapter, config }) => {
setAdapter(getAdapter());
_config = config;
buildTempFolder = config.build.server;
functionFolder = new URL('./functions/render.func/', config.outDir);
serverEntry = config.build.serverEntry;

if (config.output === 'static') {
throw new Error(`
Expand All @@ -37,11 +50,12 @@ export default function vercelEdge(): AstroIntegration {
`);
}
},
'astro:build:start': async ({ buildConfig }) => {
buildConfig.serverEntry = serverEntry = 'entry.js';
buildConfig.client = new URL('./static/', _config.outDir);
buildConfig.server = buildTempFolder = new URL('./dist/', _config.root);
functionFolder = new URL('./functions/render.func/', _config.outDir);
'astro:build:start': ({ buildConfig }) => {
if(needsBuildConfig) {
buildConfig.client = new URL('./static/', _config.outDir);
buildTempFolder = buildConfig.server = new URL('./dist/', _config.root);
serverEntry = buildConfig.serverEntry = 'entry.js';
}
},
'astro:build:done': async ({ routes }) => {
// Copy necessary files (e.g. node_modules/)
Expand Down

0 comments on commit 8debb79

Please sign in to comment.