+1
-1
packages/core/templates/presentation.eta
+1
-1
packages/core/templates/presentation.eta
+11
-1
packages/server/dev.ts
+11
-1
packages/server/dev.ts
···
22
22
return new BroadcastChannel("live-reload");
23
23
}
24
24
25
+
const ROOT_ROUTE = new URLPattern({ pathname: "/" });
25
26
const LIVE_RELOAD_ROUTE = new URLPattern({ pathname: "/live-reload" });
26
-
const STATIC_ROUTE = new URLPattern({ pathname: "/static/*" });
27
+
const STATIC_ROUTE = new URLPattern({ pathname: "/static/bundle.js" });
27
28
28
29
function makeHandler(path: string) {
29
30
const channel = openChannel();
···
33
34
const staticMatch = STATIC_ROUTE.exec(req.url);
34
35
35
36
if (liveReloadMatch) {
37
+
// Serve Websocket route
36
38
const upgrade = req.headers.get("upgrade") ?? "";
37
39
if (upgrade.toLowerCase() !== "websocket") {
38
40
return new Response("no upgrade specified");
···
46
48
47
49
return response;
48
50
} else if (staticMatch) {
51
+
// Bundle and serve runtime
49
52
const { outputFiles } = await esbuild.build({
50
53
stdin: {
51
54
contents: `import "@morkdeck/wc"`,
···
62
65
"Cache-Control": "no-store",
63
66
},
64
67
});
68
+
} else if (!ROOT_ROUTE.exec(req.url)) {
69
+
// Redirect to root and log 404
70
+
console.info(`Redirecting ${req.url} to origin`);
71
+
72
+
const url = new URL(req.url);
73
+
74
+
return Response.redirect(url.origin, 301);
65
75
}
66
76
67
77
const html = await renderPresentationHtml(path, { devMode: true });