From eab2c0e7e62c8aef94686b543578049f664fcd3a Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Sun, 17 Mar 2019 12:46:36 -0400 Subject: Update stats --- src/html/admin.html | 19 +++++++++++++++++-- src/server.js | 8 ++++---- 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/html/admin.html b/src/html/admin.html index c42ee95..b2b1f64 100644 --- a/src/html/admin.html +++ b/src/html/admin.html @@ -14,8 +14,9 @@ el: '#stats', data: { stats: {session: [], url: []}, - showSessionTable: true, - showUrlTable: true, + showSessionTable: false, + showUrlTable: false, + showLogData: false, }, created() { fetch(new Request('/admin/stats')).then(response => response.json()) @@ -76,6 +77,20 @@ {{item.c}} +
+ + +
+ + + + + + + + + +
DateSessionMethodPath
{{item.createdAt}}{{item.session.substring(0,10)}}...{{item.method}}{{item.url.substring(0, Math.min(30, item.url.length))}}{{item.c}}
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); -- cgit v1.2.3