2024-02-27 11:15:27 +00:00
|
|
|
import type { SSRManifest } from 'astro';
|
2023-07-27 18:24:39 +02:00
|
|
|
import { NodeApp, applyPolyfills } from 'astro/app/node';
|
2024-02-27 11:15:27 +00:00
|
|
|
import createMiddleware from './middleware.js';
|
2024-01-17 13:10:43 +00:00
|
|
|
import { createStandaloneHandler } from './standalone.js';
|
2022-10-12 17:25:51 -04:00
|
|
|
import startServer from './standalone.js';
|
2023-09-13 16:49:22 +02:00
|
|
|
import type { Options } from './types.js';
|
2022-03-24 07:26:25 -04:00
|
|
|
|
2024-06-10 16:43:48 +02:00
|
|
|
// 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(() => {});
|
|
|
|
|
2023-07-27 18:24:39 +02:00
|
|
|
applyPolyfills();
|
2023-01-11 00:59:20 +08:00
|
|
|
export function createExports(manifest: SSRManifest, options: Options) {
|
2022-03-24 17:08:36 -04:00
|
|
|
const app = new NodeApp(manifest);
|
2024-01-25 11:23:27 +01:00
|
|
|
options.trailingSlash = manifest.trailingSlash;
|
2022-03-24 07:26:25 -04:00
|
|
|
return {
|
2023-11-28 08:46:26 -05:00
|
|
|
options: options,
|
2024-01-17 13:10:43 +00:00
|
|
|
handler:
|
2024-01-17 13:11:46 +00:00
|
|
|
options.mode === 'middleware' ? createMiddleware(app) : createStandaloneHandler(app, options),
|
2023-02-03 00:12:22 +00:00
|
|
|
startServer: () => startServer(app, options),
|
2022-03-24 11:27:15 +00:00
|
|
|
};
|
2022-03-24 07:26:25 -04:00
|
|
|
}
|
|
|
|
|
2022-10-12 17:25:51 -04:00
|
|
|
export function start(manifest: SSRManifest, options: Options) {
|
2022-10-12 21:27:56 +00:00
|
|
|
if (options.mode !== 'standalone' || process.env.ASTRO_NODE_AUTOSTART === 'disabled') {
|
2022-10-12 17:25:51 -04:00
|
|
|
return;
|
2022-09-28 16:55:27 -04:00
|
|
|
}
|
|
|
|
|
2022-10-12 17:25:51 -04:00
|
|
|
const app = new NodeApp(manifest);
|
|
|
|
startServer(app, options);
|
2022-03-24 07:26:25 -04:00
|
|
|
}
|