-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.ts
29 lines (25 loc) · 782 Bytes
/
server.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
import { apiHandler } from "./api_handler.ts";
async function handler(request: Request) {
const { pathname, searchParams } = new URL(request.url);
console.log({ pathname, searchParams: [...searchParams.entries()] });
if (pathname === "/") {
return new Response(await Deno.readFile("./index.html"), {
headers: { "Content-Type": "text/html" },
});
}
if (pathname === "/favicon.svg") {
return new Response(await Deno.readFile("./favicon.svg"), {
headers: { "Content-Type": "image/svg+xml" },
});
}
if (pathname === "/api") {
return apiHandler(searchParams);
}
return new Response("404 Not Found", {
status: 404,
statusText: "Not Found",
});
}
Deno.serve(async (request: Request) => {
return await handler(request);
});