-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
34 lines (30 loc) · 873 Bytes
/
main.ts
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
31
32
33
34
import { type Route, route } from "@std/http/route";
import { serveDir } from "@std/http/file-server";
import { api } from "./api.ts";
const routes: Route[] = [
{
pattern: new URLPattern({ pathname: "/api/v1/todos" }),
handler: api.todos.getOrCreateItem,
},
{
pattern: new URLPattern({ pathname: "/api/v1/todos/:ulid/edit" }),
handler: api.todos.patchItem,
},
{
pattern: new URLPattern({ pathname: "/api/v1/todos/:ulid" }),
handler: api.todos.getOrDeleteItem,
},
{
pattern: new URLPattern({ pathname: "/" }),
handler: (req: Request) => serveDir(req, { fsRoot: "public" }),
},
];
function defaultHandler(_req: Request) {
return new Response("Not found", { status: 404 });
}
const handler = route(routes, defaultHandler);
export default {
fetch(req) {
return handler(req);
},
} satisfies Deno.ServeDefaultExport;