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 | |
parent | c30218c68330f1dbcca99983f2f7f7d5274b1832 (diff) |
Update stats
Diffstat (limited to 'src')
-rw-r--r-- | src/html/admin.html | 19 | ||||
-rw-r--r-- | src/server.js | 8 |
2 files changed, 21 insertions, 6 deletions
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 @@ <td>{{item.c}}</td> </tr> </table> + <div> + <input type="checkbox" id="showLog" v-model="showLogData"> + <label for="showLog">Show Log</label> + </div> + <table class="table log-table" v-if="showLogData"> + <tr><th>Date</th><th>Session</th><th>Method</th><th>Path</th></tr> + <tr v-for="item in stats.log"> + <td>{{item.createdAt}}</td> + <td>{{item.session.substring(0,10)}}...</td> + <td>{{item.method}}</td> + <td>{{item.url.substring(0, Math.min(30, item.url.length))}}</td> + <td>{{item.c}}</td> + </tr> + </table> </div> </body> 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); |