-
Notifications
You must be signed in to change notification settings - Fork 11
/
app.js
59 lines (46 loc) · 1.56 KB
/
app.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
/* Env config and Env Initialiser */
let argv = require('minimist')(process.argv.slice(2));
// console.log(argv);
let { initEnv, makeid } = require('./config/config');
const env = initEnv(argv.env)
/* dependencies */
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
/* Database handlers */
let { mongoose } = require('./database/mongoose');
let session = require('express-session');
const MongoStore = require('connect-mongo')(session);
let path = require('path');
/* body parser */
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
/* Session */
app.use(session({
secret: makeid(12),
resave: false,
saveUninitialized: false,
cookie: { secure: false },
store: new MongoStore({ mongooseConnection: mongoose.connection })
}))
/* view engine */
// app.set('views', __dirname + '/views');
// app.set('view engine', 'ejs');
/* Env Controller */
let controlEnv = require('./handlers/middlewares/controllEnv');
controlEnv(app, env, __dirname);
/* Services */
let { Service, serviceInit, addService } = require('./services/initService');
let service = (argv.service == null) ? Service.All() : argv.service.split(',');
serviceInit(app, service);
app.set('port', (process.env.PORT || 5000))
app.get('*', (req, res) => {
// res.sendFile(path.join(__dirname + '/client/public/index.html'));
res.send('404')
});
app.listen(app.get('port'), process.env.IP, function () {
console.log(`Server started at ${app.get('port')}`);
console.log(`env: ${process.env.NODE_ENV}`);
});