-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.ts
34 lines (28 loc) · 986 Bytes
/
server.ts
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
import { renderApplication } from "@angular/platform-server";
import bootstrap from "./src/main.server";
interface Env {
ASSETS: { fetch: typeof fetch };
}
// We attach the Cloudflare `fetch()` handler to the global scope
// so that we can export it when we process the Angular output.
// See tools/bundle.mjs
async function workerFetchHandler(request: Request, env: Env) {
const url = new URL(request.url);
console.log("render SSR", url.href);
// Get the root `index.html` content.
const indexUrl = new URL("/", url);
const indexResponse = await env.ASSETS.fetch(new Request(indexUrl));
const document = await indexResponse.text();
const content = await renderApplication(bootstrap, {
document,
url: url.pathname,
});
// console.log("rendered SSR", content);
return new Response(content, indexResponse);
}
export default {
fetch: (request: Request, env: Env) =>
(globalThis as any)["__zone_symbol__Promise"].resolve(
workerFetchHandler(request, env)
),
};