2022-06-17 00:31:08 +00:00
|
|
|
import type { SSRManifest } from 'astro';
|
|
|
|
import { App } from 'astro/app';
|
2022-04-19 15:22:15 +00:00
|
|
|
|
2022-07-19 20:10:15 +00:00
|
|
|
const clientAddressSymbol = Symbol.for('astro.clientAddress');
|
|
|
|
|
2022-04-19 15:22:15 +00:00
|
|
|
export function createExports(manifest: SSRManifest) {
|
|
|
|
const app = new App(manifest);
|
|
|
|
|
2022-04-22 14:03:25 +00:00
|
|
|
const handler = async (request: Request): Promise<Response | void> => {
|
|
|
|
const url = new URL(request.url);
|
|
|
|
|
|
|
|
// If this matches a static asset, just return and Netlify will forward it
|
|
|
|
// to its static asset handler.
|
2022-04-22 14:04:54 +00:00
|
|
|
if (manifest.assets.has(url.pathname)) {
|
2022-04-22 14:03:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-04-19 15:23:07 +00:00
|
|
|
if (app.match(request)) {
|
2022-07-19 20:10:15 +00:00
|
|
|
const ip = request.headers.get('x-nf-client-connection-ip');
|
|
|
|
Reflect.set(request, clientAddressSymbol, ip);
|
2022-04-19 15:22:15 +00:00
|
|
|
return app.render(request);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Response(null, {
|
|
|
|
status: 404,
|
2022-04-19 15:23:07 +00:00
|
|
|
statusText: 'Not found',
|
2022-04-19 15:22:15 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-04-19 15:23:07 +00:00
|
|
|
return { default: handler };
|
2022-04-19 15:22:15 +00:00
|
|
|
}
|