tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
289
fork
atom
a tool for shared writing and social publishing
289
fork
atom
overview
issues
27
pulls
pipelines
add not-found page for non-existent docs
awarm.space
1 year ago
b1199d24
8f065a54
+33
-7
2 changed files
expand all
collapse all
unified
split
app
not-found
page.tsx
middleware.ts
+18
app/not-found/page.tsx
···
1
1
+
export default function NotFound() {
2
2
+
return (
3
3
+
<div className="w-screen h-screen flex place-items-center bg-bg-leaflet">
4
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
5
+
<div className="font-bold">
6
6
+
Hmmm... Couldn't find that leaflet.
7
7
+
</div>
8
8
+
<div>
9
9
+
You can{" "}
10
10
+
<a href="mailto:contact@hyperlink.academy" target="blank">
11
11
+
email us
12
12
+
</a>{" "}
13
13
+
for help!
14
14
+
</div>
15
15
+
</div>
16
16
+
</div>
17
17
+
);
18
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
25
-
let { data: route } = await supabase
26
26
-
.from("custom_domain_routes")
27
27
-
.select("*")
25
25
+
if (req.nextUrl.pathname === "/not-found") return;
26
26
+
let { data: routes } = await supabase
27
27
+
.from("custom_domains")
28
28
+
.select("*, custom_domain_routes(*)")
28
29
.eq("domain", hostname)
29
29
-
.eq("route", req.nextUrl.pathname)
30
30
.single();
31
31
-
if (route)
32
32
-
return NextResponse.rewrite(
33
33
-
new URL(`/${route.view_permission_token}`, req.url),
31
31
+
if (routes) {
32
32
+
let route = routes.custom_domain_routes.find(
33
33
+
(r) => r.route === req.nextUrl.pathname,
34
34
);
35
35
+
if (route)
36
36
+
return NextResponse.rewrite(
37
37
+
new URL(`/${route.view_permission_token}`, req.url),
38
38
+
);
39
39
+
else {
40
40
+
return NextResponse.redirect(new URL("/not-found", req.url));
41
41
+
}
42
42
+
}
35
43
}