diff options
author | 2024-08-29 19:58:06 +0200 | |
---|---|---|
committer | 2024-08-29 19:58:06 +0200 | |
commit | b2d097b51e1d8845d955cee4d1e8838f96975638 (patch) | |
tree | 1593bbc71f60058579ed35219adf53b68ee3a24b /packages/integrations/node/src/server.ts | |
parent | 93a1db68cd9cf3bb2a4d9f7a8af13cbd881eb701 (diff) | |
parent | 7897044c1d95ef905a4835dafe75d5b5b323b5bf (diff) | |
download | astro-b2d097b51e1d8845d955cee4d1e8838f96975638.tar.gz astro-b2d097b51e1d8845d955cee4d1e8838f96975638.tar.zst astro-b2d097b51e1d8845d955cee4d1e8838f96975638.zip |
Merge `vercel` and `node` into main #366
Diffstat (limited to 'packages/integrations/node/src/server.ts')
-rw-r--r-- | packages/integrations/node/src/server.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/packages/integrations/node/src/server.ts b/packages/integrations/node/src/server.ts new file mode 100644 index 000000000..1bb27e002 --- /dev/null +++ b/packages/integrations/node/src/server.ts @@ -0,0 +1,34 @@ +import type { SSRManifest } from 'astro'; +import { NodeApp, applyPolyfills } from 'astro/app/node'; +import createMiddleware from './middleware.js'; +import { createStandaloneHandler } from './standalone.js'; +import startServer from './standalone.js'; +import type { Options } from './types.js'; +// This needs to run first because some internals depend on `crypto` +applyPolyfills(); + +// Won't throw if the virtual module is not available because it's not supported in +// the users's astro version or if astro:env is not enabled in the project +await import('astro/env/setup') + .then((mod) => mod.setGetEnv((key) => process.env[key])) + .catch(() => {}); + +export function createExports(manifest: SSRManifest, options: Options) { + const app = new NodeApp(manifest); + options.trailingSlash = manifest.trailingSlash; + return { + options: options, + handler: + options.mode === 'middleware' ? createMiddleware(app) : createStandaloneHandler(app, options), + startServer: () => startServer(app, options), + }; +} + +export function start(manifest: SSRManifest, options: Options) { + if (options.mode !== 'standalone' || process.env.ASTRO_NODE_AUTOSTART === 'disabled') { + return; + } + + const app = new NodeApp(manifest); + startServer(app, options); +} |