@@ -4,7 +4,8 @@ import { Hono } from "hono";
44import { renderToString } from "react-dom/server" ;
55import { getShareData } from "./blob" ;
66import { trimTrailingSlash } from "hono/trailing-slash" ;
7- import { BaseHeader , getAssetPath , HmrScript } from "./utils" ;
7+ import { BaseHeader , defaultCode , getAssetPath , HmrScript } from "./utils" ;
8+ import { notFound } from "./routes/404" ;
89
910// This must be exported for the dev server to work
1011export const app = new Hono ( ) ;
@@ -24,7 +25,7 @@ app.use(trimTrailingSlash());
2425app . get ( "/" , ( c ) => c . redirect ( "/parameters" ) ) ;
2526
2627// Serves the main web application. This must come after the API route.
27- app . get ( "/parameters/:shareId?/:example?" , async ( c ) => {
28+ app . get ( "/parameters/:shareId?/:example?" , async ( c , next ) => {
2829 const getExampleCode = async ( ) : Promise < string | null > => {
2930 const { shareId, example } = c . req . param ( ) ;
3031
@@ -33,14 +34,17 @@ app.get("/parameters/:shareId?/:example?", async (c) => {
3334 return shareData ?. code ?? null ;
3435 }
3536
36- if ( ! example ) {
37- return null ;
37+ if ( example ) {
38+ return examples [ example ] ?? null ;
3839 }
3940
40- return examples [ example ] ?? null ;
41+ return defaultCode ;
4142 } ;
4243
4344 const exampleCode = await getExampleCode ( ) ;
45+ if ( ! exampleCode ) {
46+ return notFound ( c , next ) ;
47+ }
4448
4549 return c . html (
4650 [
@@ -55,13 +59,13 @@ app.get("/parameters/:shareId?/:example?", async (c) => {
5559 </ head >
5660 < body >
5761 < div id = "root" > </ div >
58- { exampleCode ? (
5962 < script type = "module" > { `window.CODE = ${ JSON . stringify ( exampleCode ) } ` } </ script >
60- ) : null }
6163 < script type = "module" src = { getAssetPath ( "/src/client/index.tsx" ) } > </ script >
6264 </ body >
6365 </ html > ,
6466 ) ,
6567 ] . join ( "\n" ) ,
6668 ) ;
6769} ) ;
70+
71+ app . get ( "*" , notFound ) ;
0 commit comments