astro/packages/integrations/netlify/src/netlify-edge-functions.ts
Ben Holmes 4acd245d8f
Refactor: remove Deno shim to esbuild "banner" (#3734)
* refactor: remove Deno shim to esbuild "banner"

* refactor: move shim to const

* refactor: add shim to netlify edge

* chore: changeset
2022-06-27 17:20:28 -04:00

26 lines
624 B
TypeScript

import type { 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;
}
if (app.match(request)) {
return app.render(request);
}
return new Response(null, {
status: 404,
statusText: 'Not found',
});
};
return { default: handler };
}