summaryrefslogtreecommitdiff
path: root/packages/integrations/node/src/server.ts
blob: 202e66b7e933928869f72ec024dc1eb82d45b503 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import type { SSRManifest } from 'astro';
import type { Options } from './types';
import { polyfill } from '@astrojs/webapi';
import { NodeApp } from 'astro/app/node';
import middleware from './middleware.js';
import startServer from './standalone.js';

polyfill(globalThis, {
	exclude: 'window document',
});

export function createExports(manifest: SSRManifest) {
	const app = new NodeApp(manifest);
	return {
		handler: middleware(app)
	};
}

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);
}