Skip to content

Instantly share code, notes, and snippets.

@krismuniz
Last active March 17, 2020 04:42
Show Gist options
  • Select an option

  • Save krismuniz/e8497684c3108d59bd5735958ba491a8 to your computer and use it in GitHub Desktop.

Select an option

Save krismuniz/e8497684c3108d59bd5735958ba491a8 to your computer and use it in GitHub Desktop.
Minimal Deno server.
import { serve, ServerRequest, Server } from "https://deno.land/[email protected]/http/server.ts";
type Handler = (req: ServerRequest) => void
export default async function (port: number, handler: Handler) {
const s: Server = serve({ port });
for await (const req of s) {
handler(req)
}
return s
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment