Generate web slides from Markdoc
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

graham.systems c9551333 573c529c

verified
+12 -2
+1 -1
packages/core/templates/presentation.eta
··· 5 6 <%~ include("./partials/slide-styles") %> 7 8 - <script src="/static/morkdeck.js"></script> 9 </head> 10 <body> 11 <%~ it.body %>
··· 5 6 <%~ include("./partials/slide-styles") %> 7 8 + <script src="static/bundle.js"></script> 9 </head> 10 <body> 11 <%~ it.body %>
+11 -1
packages/server/dev.ts
··· 22 return new BroadcastChannel("live-reload"); 23 } 24 25 const LIVE_RELOAD_ROUTE = new URLPattern({ pathname: "/live-reload" }); 26 - const STATIC_ROUTE = new URLPattern({ pathname: "/static/*" }); 27 28 function makeHandler(path: string) { 29 const channel = openChannel(); ··· 33 const staticMatch = STATIC_ROUTE.exec(req.url); 34 35 if (liveReloadMatch) { 36 const upgrade = req.headers.get("upgrade") ?? ""; 37 if (upgrade.toLowerCase() !== "websocket") { 38 return new Response("no upgrade specified"); ··· 46 47 return response; 48 } else if (staticMatch) { 49 const { outputFiles } = await esbuild.build({ 50 stdin: { 51 contents: `import "@morkdeck/wc"`, ··· 62 "Cache-Control": "no-store", 63 }, 64 }); 65 } 66 67 const html = await renderPresentationHtml(path, { devMode: true });
··· 22 return new BroadcastChannel("live-reload"); 23 } 24 25 + const ROOT_ROUTE = new URLPattern({ pathname: "/" }); 26 const LIVE_RELOAD_ROUTE = new URLPattern({ pathname: "/live-reload" }); 27 + const STATIC_ROUTE = new URLPattern({ pathname: "/static/bundle.js" }); 28 29 function makeHandler(path: string) { 30 const channel = openChannel(); ··· 34 const staticMatch = STATIC_ROUTE.exec(req.url); 35 36 if (liveReloadMatch) { 37 + // Serve Websocket route 38 const upgrade = req.headers.get("upgrade") ?? ""; 39 if (upgrade.toLowerCase() !== "websocket") { 40 return new Response("no upgrade specified"); ··· 48 49 return response; 50 } else if (staticMatch) { 51 + // Bundle and serve runtime 52 const { outputFiles } = await esbuild.build({ 53 stdin: { 54 contents: `import "@morkdeck/wc"`, ··· 65 "Cache-Control": "no-store", 66 }, 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); 75 } 76 77 const html = await renderPresentationHtml(path, { devMode: true });