Skip to content

Instantly share code, notes, and snippets.

@mayankchoubey
Created June 30, 2021 06:24
Show Gist options
  • Save mayankchoubey/6a802744d2227d28cd5677679bed1ef0 to your computer and use it in GitHub Desktop.
Save mayankchoubey/6a802744d2227d28cd5677679bed1ef0 to your computer and use it in GitHub Desktop.
URL shortener - server.ts
import {PORT as port} from "./constants.ts";
import {handleRequest} from "./router.ts";
if(!window.location) {
console.error("ERROR: Location must be specified with --location");
Deno.exit(1);
}
const listener = Deno.listen({port});
for await(const conn of listener)
handleNewConnection(conn);
async function handleNewConnection(conn: Deno.Conn) {
for await(const req of Deno.serveHttp(conn))
await handleRequest(req.request, req.respondWith);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment