Skip to content

Instantly share code, notes, and snippets.

@modster
Created July 12, 2022 12:32
Show Gist options
  • Save modster/bb0a520ca2bd36b9b9efc0a084672001 to your computer and use it in GitHub Desktop.
Save modster/bb0a520ca2bd36b9b9efc0a084672001 to your computer and use it in GitHub Desktop.
Deno HTTP Server
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