a tool for shared writing and social publishing

add not-found page for non-existent docs

+33 -7
+18
app/not-found/page.tsx
··· 1 + export default function NotFound() { 2 + return ( 3 + <div className="w-screen h-screen flex place-items-center bg-bg-leaflet"> 4 + <div className="bg-bg-page mx-auto p-4 border border-border rounded-md flex flex-col text-center justify-centergap-1 w-fit"> 5 + <div className="font-bold"> 6 + Hmmm... Couldn&apos;t find that leaflet. 7 + </div> 8 + <div> 9 + You can{" "} 10 + <a href="mailto:contact@hyperlink.academy" target="blank"> 11 + email us 12 + </a>{" "} 13 + for help! 14 + </div> 15 + </div> 16 + </div> 17 + ); 18 + }
+15 -7
middleware.ts
··· 22 22 export default async function middleware(req: NextRequest) { 23 23 let hostname = req.headers.get("host")!; 24 24 if (hostname === "leaflet.pub") return; 25 - let { data: route } = await supabase 26 - .from("custom_domain_routes") 27 - .select("*") 25 + if (req.nextUrl.pathname === "/not-found") return; 26 + let { data: routes } = await supabase 27 + .from("custom_domains") 28 + .select("*, custom_domain_routes(*)") 28 29 .eq("domain", hostname) 29 - .eq("route", req.nextUrl.pathname) 30 30 .single(); 31 - if (route) 32 - return NextResponse.rewrite( 33 - new URL(`/${route.view_permission_token}`, req.url), 31 + if (routes) { 32 + let route = routes.custom_domain_routes.find( 33 + (r) => r.route === req.nextUrl.pathname, 34 34 ); 35 + if (route) 36 + return NextResponse.rewrite( 37 + new URL(`/${route.view_permission_token}`, req.url), 38 + ); 39 + else { 40 + return NextResponse.redirect(new URL("/not-found", req.url)); 41 + } 42 + } 35 43 }