websrv: redirect
This commit is contained in:
parent
29329702da
commit
47cc62b767
|
@ -24,6 +24,11 @@ http.createServer(async (req, res, r) => {
|
||||||
body
|
body
|
||||||
}) => res.writeHead(code, { "Content-Type": `${type}; charset=utf-8` }).end(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);
|
!(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}`);
|
console.log(`[${(new Date()).toLocaleTimeString()}] ${res.statusCode} ${req.method}\t${req.url.pathname}`);
|
||||||
}).listen(cfg.websrv.port, () => setTimeout(() => {
|
}).listen(cfg.websrv.port, () => setTimeout(() => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user