summaryrefslogtreecommitdiff
path: root/benchmark/packages/timer/src/server.ts
blob: 28a406841a847f73972de41573f9bfd4da96790c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { polyfill } from '@astrojs/webapi';
import type { SSRManifest } from 'astro';
import { NodeApp } from 'astro/app/node';
import type { IncomingMessage, ServerResponse } from 'node:http';

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

export function createExports(manifest: SSRManifest) {
	const app = new NodeApp(manifest);
	return {
		handler: async (req: IncomingMessage, res: ServerResponse) => {
			const start = performance.now();
			await app.render(req);
			const end = performance.now();
			res.write(end - start + '');
			res.end();
		},
	};
}