-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
53 lines (48 loc) · 1.57 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
var express = require('express'),
session = require('express-session'),
bodyParser = require('body-parser'),
methodOverride = require('method-override'),
partials = require('express-partials'),
helmet = require('helmet'),
passport = require('./session'),
flash = require('connect-flash'),
messages = require('express-messages');
var app = express();
// configure Express
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(helmet());
app.use(express.static(__dirname + '/public'));
app.use(partials());
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(methodOverride());
app.use(session({secret: 'keyboard cat', resave: false, saveUninitialized: false}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
app.use(function (req, res, next) {
res.locals.messager = messages(req, res);
next();
});
// Configure routes
app.use('/', require('./routes/index'));
app.use('/user', require('./routes/users'));
app.use('/poll', require('./routes/polls'));
app.use('/auth', require('./routes/auth'));
// catch 404 and forward to error handler
app.use(function (req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handler
// no stacktraces leaked to user unless in development environment
app.use(function (err, req, res, next) {
res.status(err.status || 500);
res.render('pages/error', {
message: err.message,
error: (app.get('env') === 'development') ? err : {}
});
});
module.exports = app;