diff options
author | Mark Powers <markppowers0@gmail.com> | 2019-03-17 12:46:36 -0400 |
---|---|---|
committer | Mark Powers <markppowers0@gmail.com> | 2019-03-17 12:46:36 -0400 |
commit | eab2c0e7e62c8aef94686b543578049f664fcd3a (patch) | |
tree | 251c6a77d29cbc3311cc937a330416e0e0553339 /src/server.js | |
parent | c30218c68330f1dbcca99983f2f7f7d5274b1832 (diff) |
Update stats
Diffstat (limited to 'src/server.js')
-rw-r--r-- | src/server.js | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/server.js b/src/server.js index bf415ed..06a3ec5 100644 --- a/src/server.js +++ b/src/server.js @@ -42,7 +42,7 @@ function listen(port) { function setUpRoutes(models, jwtFunctions, database) { // Authentication routine server.use(function (req, res, next) { - if (req.path.startsWith("/admin")) { + if (req.path.toLowerCase().startsWith("/admin")) { let cookie = req.cookies.authorization if (!cookie) { console.debug("Redirecting to login - no cookie") @@ -72,9 +72,8 @@ function setUpRoutes(models, jwtFunctions, database) { let cookie = req.cookies.session; if (!cookie) { cookie = uuidv4(); - res.cookie('session', session, { expires: new Date(Date.now() + (1000 * 60 * 60)) }); + res.cookie('session', cookie, { expires: new Date(Date.now() + (1000 * 60 * 60)) }); } - models.requests.create({ createdAt: new Date(), session: cookie, method: req.method, url: req.originalUrl }); @@ -99,7 +98,8 @@ function setUpRoutes(models, jwtFunctions, database) { try { var sessionResult = await database.query("SELECT session, count(id) as c FROM requests GROUP BY session", { type: database.QueryTypes.SELECT }) var urlResult = await database.query("SELECT method, url, count(id) as c FROM requests GROUP BY method, url", { type: database.QueryTypes.SELECT }) - res.status(200).send({ session: sessionResult, url: urlResult }); + var logResult = await database.query("SELECT createdAt, session, method, url FROM requests order by createdAt desc limit 15", { type: database.QueryTypes.SELECT }) + res.status(200).send({ session: sessionResult, url: urlResult, log: logResult }); next(); } catch (e) { res.status(400).send(e.message); |