114bf63e11
* Removed ignores * Migration to v3 * More changes * Remove legacy redirects * Fail when there is no ENABLE_VC_BUILD * Fix edge * Updated readme * Changeset * Added static mode * Updated documentation * Updated shim * Made edge work! * Updated changeset * Ensure empty dir * Fixed redirects for dynamic paths * Removed extra declaration * Splited imports * Updated readme * Fixed some urls * Deprecated shim! * [test]: Vercel NFT * Beautify * Edge bundle to node 14.19 Vercel runs 14.19.1 (I've checked it manually) * Re-added shim (#3304) * Added `node:` prefix * Use the same bundling as Deno for Edge * Remove esbuild * Fixed shim * Moved nft * Updated changeset * Added note about Edge * fix typo * Added support for Node 16 (vercel/vercel#7772)
34 lines
879 B
TypeScript
34 lines
879 B
TypeScript
import type { SSRManifest } from 'astro';
|
|
import { App } from 'astro/app';
|
|
import { polyfill } from '@astrojs/webapi';
|
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
|
|
import { getRequest, setResponse } from './request-transform.js';
|
|
|
|
polyfill(globalThis, {
|
|
exclude: 'window document',
|
|
});
|
|
|
|
export const createExports = (manifest: SSRManifest) => {
|
|
const app = new App(manifest);
|
|
|
|
const handler = async (req: IncomingMessage, res: ServerResponse) => {
|
|
let request: Request;
|
|
|
|
try {
|
|
request = await getRequest(`https://${req.headers.host}`, req);
|
|
} catch (err: any) {
|
|
res.statusCode = err.status || 400;
|
|
return res.end(err.reason || 'Invalid request body');
|
|
}
|
|
|
|
if (!app.match(request)) {
|
|
res.statusCode = 404;
|
|
return res.end('Not found');
|
|
}
|
|
|
|
await setResponse(res, await app.render(request));
|
|
};
|
|
|
|
return { default: handler };
|
|
};
|