diff options
Diffstat (limited to 'render.js')
-rw-r--r-- | render.js | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -3,6 +3,7 @@ const pug = require('pug') const marked = require('marked') const fs = require('fs').promises +const http = require('http') const unit = (...args) => null const log = process.env.VERBOSE ? console.log : unit @@ -226,6 +227,23 @@ const do_clean = path => tree => .then(rm_tree) .then(_ => tree) +const listen = async t => + process.env.LISTEN && + http.createServer(async (req,res) => { + const file = fs.readFile(__dirname + '/static/' + decodeURI(req.url)) + .catch(_ => fs.readFile(__dirname + '/static/' + decodeURI(req.url) + '/index.html')) + + try { + const f = await file + res.writeHead(200) + res.end(f) + } catch (e) { + console.error(e) + res.writeHead(404) + res.end("404 not found") + } + }).listen(process.env.LISTEN); + const conf = { src: './src', dest: './static'} walk(conf.src) .then(propagate_md_layout) @@ -242,4 +260,5 @@ walk(conf.src) .then(do_folder) .then(do_copy) .then(do_pug()) + .then(listen) .catch(console.error) |