-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tsx
More file actions
30 lines (24 loc) · 790 Bytes
/
main.tsx
File metadata and controls
30 lines (24 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/// <reference no-default-lib="true"/>
/// <reference lib="dom" />
/// <reference lib="dom.asynciterable" />
/// <reference lib="deno.ns" />
import { serve } from "./deps.ts";
import { Page } from "./pages/common.ts";
import { pages } from "./pages/mod.ts";
serve(async (req) => {
let match: Page | null = null;
const url = new URL(req.url);
for (const page of pages) {
const res = page.path === url.pathname;
if (res) {
match = page;
break;
}
}
// TODO: maybe proper 404 page?
if (!match) return new Response("Not Found", { status: 404 });
const response = await match.handle(req);
if (!response) return new Response("Not Found", { status: 404 });
else return response;
}, { port: 3000 });
console.log("Listening on http://localhost:3000");