Created
February 5, 2016 23:56
-
-
Save Lokua/0b9428c030da2ac34491 to your computer and use it in GitHub Desktop.
quickly serve index.html and and other static assets in a directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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