0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-03 22:29:08 -05:00
astro/packages/integrations/vercel/src/serverless/entrypoint.ts
Emanuele Stoppa 9680cf2780 [ci] format
2024-01-17 13:11:46 +00:00

24 lines
862 B
TypeScript

import type { SSRManifest } from 'astro';
import { applyPolyfills, NodeApp } from 'astro/app/node';
import type { IncomingMessage, ServerResponse } from 'node:http';
import { ASTRO_LOCALS_HEADER } from './adapter.js';
applyPolyfills();
export const createExports = (manifest: SSRManifest) => {
const app = new NodeApp(manifest);
const handler = async (req: IncomingMessage, res: ServerResponse) => {
const clientAddress = req.headers['x-forwarded-for'] as string | undefined;
const localsHeader = req.headers[ASTRO_LOCALS_HEADER];
const locals =
typeof localsHeader === 'string'
? JSON.parse(localsHeader)
: Array.isArray(localsHeader)
? JSON.parse(localsHeader[0])
: {};
const webResponse = await app.render(req, { locals, clientAddress });
await NodeApp.writeResponse(webResponse, res);
};
return { default: handler };
};