blob: 7b88c7b1e4d18c2e6ed0d8f5d1aacbb75c606c90 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
import './shim.js';
import type { SSRManifest } from 'astro';
import { App } from 'astro/app';
type Env = {
ASSETS: { fetch: (req: Request) => Promise<Response> };
};
export function createExports(manifest: SSRManifest) {
const app = new App(manifest, false);
const fetch = async (request: Request, env: Env) => {
const { origin, pathname } = new URL(request.url);
// static assets
if (manifest.assets.has(pathname)) {
const assetRequest = new Request(`${origin}/static${pathname}`, request);
return env.ASSETS.fetch(assetRequest);
}
let routeData = app.match(request, { matchNotFound: true });
if (routeData) {
Reflect.set(
request,
Symbol.for('astro.clientAddress'),
request.headers.get('cf-connecting-ip')
);
return app.render(request, routeData);
}
return new Response(null, {
status: 404,
statusText: 'Not found',
});
};
return { default: { fetch } };
}
|