|
@@ -1,5 +1,5 @@
|
|
|
-const HELLO_WORLD_STR = "Hello, World!";
|
|
|
-const options: ResponseInit = { headers: { "Server": "Bun" } };
|
|
|
+const plainOptions: ResponseInit = { headers: { "Server": "Bun" } };
|
|
|
+const jsonOptions: ResponseInit = { headers: { "Server": "Bun", "Content-Type": "application/json" } };
|
|
|
|
|
|
const server = Bun.serve({
|
|
|
port: 8080,
|
|
@@ -7,16 +7,16 @@ const server = Bun.serve({
|
|
|
fetch(req: Request) {
|
|
|
const pathname = req.url.slice(req.url.indexOf("/", 8));
|
|
|
|
|
|
- if (pathname === "/json") {
|
|
|
- return Response.json({ message: HELLO_WORLD_STR }, options);
|
|
|
+ if (pathname == "/json") {
|
|
|
+ return new Response(JSON.stringify({ message: "Hello, World!" }), jsonOptions);
|
|
|
}
|
|
|
|
|
|
- if (pathname === "/plaintext") {
|
|
|
- return new Response(HELLO_WORLD_STR, options);
|
|
|
+ if (pathname == "/plaintext") {
|
|
|
+ return new Response("Hello, World!", plainOptions);
|
|
|
}
|
|
|
|
|
|
return new Response("", { status: 404 })
|
|
|
},
|
|
|
});
|
|
|
|
|
|
-console.log(`Listening on localhost:${server.port}`);
|
|
|
+console.log(`Listening on ${server.url}\n`);
|