2022-10-12 21:25:51 +00:00
|
|
|
import { polyfill } from '@astrojs/webapi';
|
2022-10-12 21:27:56 +00:00
|
|
|
import type { SSRManifest } from 'astro';
|
2022-06-06 16:49:53 +00:00
|
|
|
import { NodeApp } from 'astro/app/node';
|
2022-10-12 21:25:51 +00:00
|
|
|
import middleware from './middleware.js';
|
|
|
|
import startServer from './standalone.js';
|
2022-10-12 21:27:56 +00:00
|
|
|
import type { Options } from './types';
|
2022-03-24 11:26:25 +00:00
|
|
|
|
|
|
|
polyfill(globalThis, {
|
2022-03-24 11:27:15 +00:00
|
|
|
exclude: 'window document',
|
2022-03-24 11:26:25 +00:00
|
|
|
});
|
|
|
|
|
2023-01-10 16:59:20 +00:00
|
|
|
export function createExports(manifest: SSRManifest, options: Options) {
|
2022-03-24 21:08:36 +00:00
|
|
|
const app = new NodeApp(manifest);
|
2022-03-24 11:26:25 +00:00
|
|
|
return {
|
2023-01-10 16:59:20 +00:00
|
|
|
handler: middleware(app, options.mode),
|
2022-03-24 11:27:15 +00:00
|
|
|
};
|
2022-03-24 11:26:25 +00:00
|
|
|
}
|
|
|
|
|
2022-10-12 21:25:51 +00: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 21:25:51 +00:00
|
|
|
return;
|
2022-09-28 20:55:27 +00:00
|
|
|
}
|
|
|
|
|
2022-10-12 21:25:51 +00:00
|
|
|
const app = new NodeApp(manifest);
|
|
|
|
startServer(app, options);
|
2022-03-24 11:26:25 +00:00
|
|
|
}
|