astro/packages/integrations/netlify/src/netlify-edge-functions.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

28 lines
643 B
TypeScript
Raw Normal View History

import './edge-shim.js';
import { SSRManifest } from 'astro';
import { App } from 'astro/app';
export function createExports(manifest: SSRManifest) {
const app = new App(manifest);
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.
if(manifest.assets.has(url.pathname)) {
return;
}
2022-04-19 15:23:07 +00:00
if (app.match(request)) {
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:23:07 +00:00
return { default: handler };
}