Generate web slides from Markdoc

fix(server): narrow static path matcher, redirect 404s

graham.systems c9551333 573c529c

verified
Changed files
+12 -2
packages
core
templates
server
+1 -1
packages/core/templates/presentation.eta
··· 5 5 6 6 <%~ include("./partials/slide-styles") %> 7 7 8 - <script src="/static/morkdeck.js"></script> 8 + <script src="static/bundle.js"></script> 9 9 </head> 10 10 <body> 11 11 <%~ it.body %>
+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 });