Skip to content

Instantly share code, notes, and snippets.

@Lokua
Created February 5, 2016 23:56
Show Gist options
  • Save Lokua/0b9428c030da2ac34491 to your computer and use it in GitHub Desktop.
Save Lokua/0b9428c030da2ac34491 to your computer and use it in GitHub Desktop.
quickly serve index.html and and other static assets in a directory
'use strict'
const serve = require('koa-static')
new (require('koa'))()
.use(serve(`${__dirname}`))
.use(function* (next) {
return this.body = yield new Promise((resolve, reject) => {
require('fs').readFile(`${__dirname}/index.html`, 'utf8',
(err, body) => resolve(body))
})
})
.listen(3000, () => console.log('demo server listening on port 3000'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment