websrv: time measurement
This commit is contained in:
parent
962034b11f
commit
80f6dbf271
|
@ -10,6 +10,8 @@ import "./inc/routes/api.mjs";
|
||||||
import "./inc/routes/static.mjs";
|
import "./inc/routes/static.mjs";
|
||||||
|
|
||||||
http.createServer(async (req, res, r) => {
|
http.createServer(async (req, res, r) => {
|
||||||
|
const t_start = process.hrtime();
|
||||||
|
|
||||||
req.url = url.parse(req.url.replace(/(?!^.)(\/+)?$/, ''));
|
req.url = url.parse(req.url.replace(/(?!^.)(\/+)?$/, ''));
|
||||||
req.url.split = req.url.pathname.split("/").slice(1);
|
req.url.split = req.url.pathname.split("/").slice(1);
|
||||||
req.url.qs = querystring.parse(req.url.query);
|
req.url.qs = querystring.parse(req.url.query);
|
||||||
|
@ -30,7 +32,7 @@ http.createServer(async (req, res, r) => {
|
||||||
}).end();
|
}).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()}] ${(process.hrtime(t_start)[1] / 1e5).toFixed(2)}ms\t${res.statusCode} ${req.method}\t${req.url.pathname}`);
|
||||||
}).listen(cfg.websrv.port, () => setTimeout(() => {
|
}).listen(cfg.websrv.port, () => setTimeout(() => {
|
||||||
console.log(`f0ck is listening on port ${cfg.websrv.port}.`);
|
console.log(`f0ck is listening on port ${cfg.websrv.port}.`);
|
||||||
}, 500));
|
}, 500));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user