1// Hand-rolled SSR shape (the solidjs-ssr example / docs-site pattern): the
2// client build emits index.html — an asset that would shadow `/` under
3// assets-first routing — so the worker runs first, renders every page, and
4// delegates real static files to the ASSETS binding itself.
5type Env = {
6 ASSETS: {
7 fetch(request: Request): Promise<Response>;
8 };
9};
10
11const page = (path: string) => `<!doctype html>
12<html lang="en">
13 <head>
14 <meta charset="UTF-8" />
15 <title>worker-first rendered</title>
16 </head>
17 <body>
18 <div id="app">worker-first-rendered:${path}</div>
19 </body>
20</html>
21`;
22
23export default {
24 async fetch(request: Request, env: Env): Promise<Response> {
25 const url = new URL(request.url);
26 if (url.pathname.startsWith("/assets/") || url.pathname === "/robots.txt") {
27 return env.ASSETS.fetch(request);
28 }
29 return new Response(page(url.pathname), {
30 headers: { "content-type": "text/html; charset=utf-8" },
31 });
32 },
33};