Skip to content

Commit c91be85

Browse files
authored
Add a simple admin UI to show the session length (#1203)
Related to #604 Auto-merge
1 parent 01ff167 commit c91be85

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

controllers/admin.js

+30-1
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,39 @@ exports.adminProcessCloneView = function (aReq, aRes, aNext) {
340340
isAdminProcessCloneView: true,
341341
clone: clone
342342
}
343-
344343
});
345344
}
346345

346+
exports.adminSessionLengthView = function (aReq, aRes, aNext) {
347+
if (!userIsAdmin(aReq)) {
348+
statusCodePage(aReq, aRes, aNext, {
349+
statusCode: 403,
350+
statusMessage: 'This page is only accessible by admins.'
351+
});
352+
return;
353+
}
354+
355+
aReq.sessionStore.length(function (aErr, aLength) {
356+
if (aErr) {
357+
statusCodePage(aReq, aRes, aNext, {
358+
statusCode: 520,
359+
statusMessage: 'Unknown error.'
360+
});
361+
return;
362+
}
363+
364+
statusCodePage(aReq, aRes, aNext, {
365+
statusCode: 200,
366+
statusMessage: 'session length: ' + aLength,
367+
isCustomView: true,
368+
statusData: {
369+
isAdminSessionLengthView: true,
370+
length: aLength
371+
}
372+
});
373+
});
374+
};
375+
347376
// View everything about current deployed `./package.json`
348377
exports.adminNpmPackageView = function (aReq, aRes, aNext) {
349378
//

routes.js

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ module.exports = function (aApp) {
100100
aApp.route('/admin/git/short').get(admin.adminGitShortView);
101101
aApp.route('/admin/git/branch').get(admin.adminGitBranchView);
102102
aApp.route('/admin/process/clone').get(admin.adminProcessCloneView);
103+
aApp.route('/admin/session/length').get(admin.adminSessionLengthView);
103104
aApp.route('/admin/npm/package').get(admin.adminNpmPackageView);
104105
aApp.route('/admin/npm/list').get(admin.adminNpmListView);
105106
aApp.route('/admin/api').get(admin.adminApiKeysPage);

views/pages/adminPage.html

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
<a href="/admin/process/clone" class="list-group-item">
2323
<i class="fa fa-fw fa-database"></i> Show clone
2424
</a>
25+
<a href="/admin/session/length" class="list-group-item">
26+
<i class="fa fa-fw fa-database"></i> Show session length
27+
</a>
2528
<a href="/admin/npm/package" class="list-group-item">
2629
<i class="fa fa-fw fa-database"></i> Raw <code>./package.json</code> JSON data
2730
</a>

views/pages/statusCodePage.html

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ <h1 class="status-code text-center">{{statusCode}}</h1>
4141
{{#isAdminProcessCloneView}}
4242
Clone: <strong>{{clone}}</strong>
4343
{{/isAdminProcessCloneView}}
44+
{{#isAdminSessionLengthView}}
45+
Session Length: <strong>{{length}}</strong>
46+
{{/isAdminSessionLengthView}}
4447
{{/statusData}}
4548
{{/isCustomView}}
4649
{{^isCustomView}}

0 commit comments

Comments
 (0)