-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroutes.js
More file actions
77 lines (62 loc) · 2.28 KB
/
routes.js
File metadata and controls
77 lines (62 loc) · 2.28 KB
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
var passport = require('passport');
var
home = require('./routes/home'),
admin = require('./routes/admin'),
test = require('./routes/test'),
api = require('./routes/api'),
MongoRest = require('mongo-rest'),
restify = require('./libs/restify')
;
function ensureAuthenticated(req, res, next) {
// no auth if running locally
if (!process.env['heroku']){
return next();
}
if (req.isAuthenticated()) {
return next();
}
res.redirect('/login');
}
var dummyWrapper = function(req, res, next) {
return next();
}
module.exports = function (app) {
// home
app.get('/', home.index);
app.get('/about', home.about);
app.get('/tests', home.specRunner);
app.get('/login', home.login);
app.post('/login', passport.authenticate('local',
{
successRedirect:'/admin',
failureRedirect:'/login'
})
);
app.get('/logout', home.logout);
// admin
app.get('/admin', ensureAuthenticated, admin.index);
app.get('/admin/localSetup', ensureAuthenticated, admin.localSetup);
app.post('/admin/localSetup', ensureAuthenticated, admin.localSetupPost);
app.get('/admin/localSetupSuccess', ensureAuthenticated, admin.localSetupSuccess);
app.get('/admin/importCsvFile', ensureAuthenticated, admin.importCsvFile);
app.post('/admin/importCsvFile', ensureAuthenticated, admin.importCsvFilePost);
// api - maps
app.get('/api', ensureAuthenticated, api.api);
app.post('/api/uploadmapimage', ensureAuthenticated, api.uploadImage);
app.post('/api/uploadmapiconimage', ensureAuthenticated, api.uploadMapIconImage);
// app models
restify(app, dummyWrapper, 'maps', require('./models/map'));
restify(app, dummyWrapper, 'locations', require('./models/location'));
restify(app, dummyWrapper, 'tunnels', require('./models/tunnel'));
restify(app, dummyWrapper, 'doctors', require('./models/doctor'));
// tests
app.get('/test/1', test.test1);
// mongo-rest
var mongoRest = new MongoRest(app, {
viewPath:'admin/resources/',
collectionViewTemplate:'resources/{{pluralName}}',
entityViewTemplate:'resources/{{singularName}}'
});
// resource based url's
mongoRest.addResource('user', require('./models/user'));
}