-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmyspend.js
executable file
·44 lines (32 loc) · 1.07 KB
/
myspend.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
const {PRODUCTION_MODE} = require('./app/constants/Environment');
const mongoose = require('./DBConnect');
const bodyParser = require('body-parser');
const session = require('express-session');
const expressMongoStore = require('express-mongoose-store')(session, mongoose);
const MongoStore = new expressMongoStore({cache_ttl: 1});
const app = require('express')();
const log = require('./app/utils/Logger');
const cors = require('cors');
const errorHandler = require('./app/middlewares/ErrorHandler');
const config = require('./config');
const routes = require('./app/routes');
const corsOptions = {
origin: PRODUCTION_MODE ? config.cors.origin : 'http://localhost:3000',
credentials: true
};
app.use(cors(corsOptions));
app.use(bodyParser.urlencoded({extended: false}));
app.use(session({
secret: config.secretSessionKey,
resave: false,
saveUninitialized: false,
store: MongoStore,
unset: 'destroy'
}));
routes.forEach((rt) => {
app.use(rt.route, rt.handler);
});
app.use(errorHandler);
app.listen(config.port, () => {
log.info("App start");
});