-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (50 loc) · 1.64 KB
/
index.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
"use strict";
var appRootPath = require('app-root-path');
require(appRootPath + '/src/common/logger.js');
var config = require(appRootPath + '/config.json');
var cors = require('cors');
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var messages = require(appRootPath + '/src/common/messages.js');
var morgan = require('morgan');
var morganOptions = require(appRootPath + '/src/common/morgan-options.js');
var port = process.env.PORT || config.port;
//Custom
var api = require('./routes/api');
var mwError = require('./middleware/error-handler');
var mwNotFoundHandler = require('./middleware/not-found-handler');
var session = require('express-session');
app.use(cors());
app.use(session({
genid: function(req) {
return require('crypto').randomBytes(48).toString('hex');
},
resave: true,
secret: '3ccl3s!aDEI',
saveUninitialized: false,
cookie: {
httpOnly: false,
maxAge: 2*60*60*1000,
path: '/'
}
}));
app.use(function(req, res, next) {
req.headers['content-type'] = 'application/json;charset=UTF-8';
return next();
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
}));
morganOptions.initialise();
app.use(morgan(morganOptions.format, morganOptions.morganOptions));
app.use('/testerror', function(req, res, next) {
return next(new Error("Test error"));
});
app.use('/api/v1', api);
app.use(mwNotFoundHandler);
app.use(mwError);
app.listen(port, function() {
console.info(messages.app.listening);
});