Skip to content

Instantly share code, notes, and snippets.

@kekru
Last active January 27, 2021 20:44
Show Gist options
  • Save kekru/751e32b5d97661f3649ce8ad8f8517ba to your computer and use it in GitHub Desktop.
Save kekru/751e32b5d97661f3649ce8ad8f8517ba to your computer and use it in GitHub Desktop.
Serve static site using deno

Serve static local site using deno and abc

This is how to create a simple static file server with deno and abc.
It serves the current dir and you can run it directly from the hosted script:

  • deno run --allow-net="0.0.0.0:80" --allow-read https://kekru.de/serve.ts
  • or deno run --allow-net="0.0.0.0:80" --allow-read https://gist.githubusercontent.com/kekru/751e32b5d97661f3649ce8ad8f8517ba/raw/2982a65c1205f72c56daf8827a8fc2f6b012600d/serve.ts
import { Application } from 'https://deno.land/x/abc@v1.0.2/mod.ts'
const app = new Application()
var localPort = 80
if (Deno.args.length > 0) {
localPort = parseInt(Deno.args[0])
}
app.static('/', '.').file('/', 'index.html').start({ port: localPort })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment