websrv: redirect

This commit is contained in:
Flummi 2020-04-06 13:15:29 +02:00
parent 29329702da
commit 47cc62b767

View File

@ -23,6 +23,11 @@ http.createServer(async (req, res, r) => {
type = "text/html",
body
}) => res.writeHead(code, { "Content-Type": `${type}; charset=utf-8` }).end(body);
res.redirect = target => res.writeHead(301, {
"Cache-Control": "no-cache, public",
"Location": target
}).end();
!(r = router.routes.getRoute(req.url.pathname, req.method)) ? res.writeHead(404).end(`404 - ${req.url.pathname}`) : await r(req, res);
console.log(`[${(new Date()).toLocaleTimeString()}] ${res.statusCode} ${req.method}\t${req.url.pathname}`);