aboutsummaryrefslogtreecommitdiff
path: root/render.js
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2020-05-28 15:00:23 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2020-05-28 15:00:23 +0200
commit6821c94d48308766cba30e262c0b092e644d5d32 (patch)
treeef044325481e647b4bccf8e6564422fc9de17e61 /render.js
parenta171273a015f5c3da68d5db9b4159ffb6b98fd79 (diff)
downloadsite-6821c94d48308766cba30e262c0b092e644d5d32.tar.gz
site-6821c94d48308766cba30e262c0b092e644d5d32.zip
Doc pour le site web
Diffstat (limited to 'render.js')
-rw-r--r--render.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/render.js b/render.js
index 1487b83..3572f60 100644
--- a/render.js
+++ b/render.js
@@ -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)