Created
September 15, 2023 18:23
-
-
Save Hexagon/9dd71c353163e87b2d2d0e6b509f3353 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --------------------------------------------------------- | |
// Bun.serve | |
const server = Bun.serve({ | |
port: 0, | |
fetch: async (req) => { | |
const url = new URL(req.url); | |
switch (url.pathname) { | |
case "/json": | |
const jsonResponse = { | |
message: "Hello, World!", | |
number: 5, | |
literal: `(${4}+${4})*${21.2}/${2}=${84.8}` | |
}; | |
return new Response(JSON.stringify(jsonResponse), { | |
status: 200, | |
headers: { | |
"content-type": "application/json; charset=utf-8", | |
} | |
}); | |
break; | |
default: | |
return new Response("Not found", { | |
status: 404 | |
}); | |
break; | |
} | |
} | |
}); | |
// --------------------------------------------------------- | |
// Deno.serve | |
// Start a HTTP server using Deno.serve | |
const server = Deno.serve( | |
{ | |
port: 0 | |
}, | |
async (req) => { | |
const url = new URL(req.url); | |
switch (url.pathname) { | |
case "/json": | |
const jsonResponse = { | |
message: "Hello, World!", | |
number: 5, | |
literal: `(${4}+${4})*${21.2}/${2}=${84.8}` | |
}; | |
return new Response(JSON.stringify(jsonResponse), { | |
status: 200, | |
headers: { | |
"content-type": "application/json; charset=utf-8", | |
} | |
}); | |
break; | |
default: | |
return new Response("Not found", { | |
status: 404 | |
}); | |
break; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment