Created
July 12, 2022 12:32
-
-
Save modster/bb0a520ca2bd36b9b9efc0a084672001 to your computer and use it in GitHub Desktop.
Deno HTTP Server
This file contains hidden or 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
import { serve } from "https://deno.land/[email protected]/http/server.ts"; | |
const port = 8080; | |
const handler = (request: Request): Response => { | |
const body = `Your user-agent is:\n\n${ | |
request.headers.get("user-agent") ?? "Unknown" | |
}`; | |
return new Response(body, { status: 200 }); | |
}; | |
console.log(`HTTP webserver running. Access it at: http://localhost:8080/`); | |
await serve(handler, { port }); | |
/** Note: | |
* Run with network permissions: deno run --allow-net webserver.ts | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment