-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
65 lines (54 loc) · 2.07 KB
/
server.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
var express = require('express'),
bodyParser = require('body-parser'),
expressValidator = require('express-validator'),
jwauth = require('./lib/jwtauth'),
acl = require('./lib/acl'),
cors = require('cors'),
path = require('path');
// sensitive
var secrets = require('./config/secrets');
// controllers
var userController = require('./controllers/user'),
authController = require('./controllers/auth');
// Database configuration
var mongoose = require('mongoose');
mongoose.connect(secrets.db);
var app = express();
// express configuration
app.set('port', process.env.PORT || 1337);
app.use(cors());
app.use(expressValidator());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));
// routes
app.post('/api/login', acl, authController.postLogin);
app.post('/api/signup', authController.postSignup);
app.post('/api/forgot', authController.getForgotPassword);
app.post('/api/reset', authController.postResetPassword);
app.post('/api/confirm', authController.postConfirmEmail);
app.post('/api/resend', authController.resendActivationEmail);
app.post('/api/add_user', jwauth, userController.addUser);
app.post('/api/delete_user', jwauth, userController.deleteUser);
app.post('/api/edit_user', jwauth, userController.postEditUser);
app.get('/api/users', userController.checkEmailAvailable);
app.get('/api/check_activated', userController.checkEmailActivated);
app.get('/api/account', jwauth, acl, userController.getAccount);
app.get('/api/manage', jwauth, acl, userController.getUsers);
app.get('/api/edit_user', jwauth, userController.getEditUser);
// handle pretty urls
app.get('*', function(req, res) {
'use strict';
res.redirect('/#' + req.originalUrl);
});
// error handling
app.use(function(err, req, res) {
'use strict';
res.status(500).body({ message: err.message });
});
// start the server
app.listen(app.get('port'), function() {
'use strict';
console.log('Express server listening on port %d in %s mode', app.get('port'), app.get('env'));
});
module.exports = app;