-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowser.js
78 lines (66 loc) · 2.47 KB
/
browser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const express = require('express');
var router = express.Router();
const adminPassword = process.env.ADMIN_PASSWORD;
const ABE_API_URI = (process.env.ABE_API_URI || 'https://abe-api-dev.herokuapp.com/')
.replace(/\/$/, '');
module.exports = function (api, rootDir) {
router.route('/').get(function(req, res) {
res.sendFile(rootDir + '/templates/uploadfile.html');
});
router.route('/views').get(ensureAuthenticated, function(req, res) {
res.sendFile(rootDir + '/templates/views.html');
});
router.route('/views/board').get(ensureAuthenticated, function(req, res) {
res.sendFile(rootDir + '/templates/board.html');
});
// Stream only View
router.route('/views/stream').get(ensureAuthenticated, function(req, res) {
res.sendFile(rootDir + '/templates/stream.html');
});
// Events only View
router.route('/views/events').get(ensureAuthenticated, function(req, res) {
res.sendFile(rootDir + '/templates/events.html');
});
router.route('/views/expo').get(ensureAuthenticated, function(req, res) {
res.sendFile(rootDir + '/templates/stream-basic.html');
});
router.route('/upload').get(function (req, res) {
res.sendFile(rootDir + '/templates/uploadfile.html');
});
router.route('/admin').get(ensureAuthenticated, function(req, res) {
res.sendFile(rootDir + '/templates/admin.html');
});
router.route('/bobs').get(api.GETallBobs);
// Show edit page on /bobs/:bobid
router.route('/bobs/:bobid')
.get(function(req, res) {
if (req.params.bobid.length === 24){
db.Bob.getOneBob({ _id: db.ObjectId(req.params.bobid)}).then(function success(data) {
if (data){
// FIXME: this is probably an error. Fix it after adding a test.
// eslint-disable-next-line no-undef
res.sendFile(path.join(rootDir, '/templates/editbob.html'));
} else {
res.status(404).send("bob not found");
}
}, function error(err) {
console.log(err);
});
} else {
res.status(404).send("bob id must be 24 characters long");
}
});
router.route('/config.js')
.get(function(req, res) {
res.type('application/javascript')
.send("const ABE_API_URI = " + JSON.stringify(ABE_API_URI) + ";");
});
return router;
};
function ensureAuthenticated(req, res, next) {
if (req.headers.auth === adminPassword | req.query.auth === adminPassword){
next();
} else {
res.status(401).send("User not authenticated");
}
}