|
@@ -1,24 +1,17 @@
|
|
|
-const options = {
|
|
|
- // Date and Content-Type headers are automatically set.
|
|
|
- headers: {
|
|
|
- "Server": "Deno",
|
|
|
- },
|
|
|
-};
|
|
|
-
|
|
|
-type HandlerFn = (req: Request) => Promise<Response> | Response;
|
|
|
-
|
|
|
-const handlers: Record<string, HandlerFn> = {
|
|
|
- "/json": () => Response.json({ message: "Hello, World!" }, options),
|
|
|
- "/plaintext": () => new Response("Hello, World!", options),
|
|
|
-};
|
|
|
+const HELLO_WORLD_STR = "Hello, World!";
|
|
|
+const options: ResponseInit = { headers: { "Server": "Deno" } };
|
|
|
|
|
|
Deno.serve({
|
|
|
+ reusePort: true,
|
|
|
handler: (req: Request) => {
|
|
|
const path = req.url.slice(req.url.indexOf("/", 8));
|
|
|
- const fn = handlers[path];
|
|
|
- return fn
|
|
|
- ? fn(req)
|
|
|
- : new Response("404 Not Found", { status: 404, ...options });
|
|
|
+ if (path == "/plaintext") {
|
|
|
+ return new Response(HELLO_WORLD_STR, options);
|
|
|
+ } else if (path == "/json") {
|
|
|
+ return Response.json({ message: HELLO_WORLD_STR }, options);
|
|
|
+ } else {
|
|
|
+ return new Response("404 Not Found", { status: 404, ...options });
|
|
|
+ }
|
|
|
},
|
|
|
onError(err) {
|
|
|
console.error(err);
|