-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
48 lines (41 loc) · 1.32 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
var logger = require('./logger');
var express = require('express');
var path = require('path');
//var favicon = require('serve-favicon');
var morganLogger = require('morgan');
var cookieParser = require('cookie-parser');
var cookieSession = require('express-session');
var bodyParser = require('body-parser');
var app = express();
app.set('port', process.env.PORT || 3000);
app.use(morganLogger('dev'));
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
app.use(cookieParser('S3CRE7'));
app.use(cookieSession({secret: 'ssshhhhh'}));
app.use(express.static(path.join(__dirname, 'public')));
var routes = require('./routes');
app.use('/', routes);
// 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 handlers
// no stacktraces leaked to user
app.use(function (err, req, res, next) {
if (err) {
res.status(500).send('500 status');
}
logger.error(err.message);
logger.error(err);
});
var models = require("./models");
models.sequelize.sync().then(function () {
var server = app.listen(app.get('port'), function () {
logger.info('Express server listening on port ' + server.address().port);
});
})