-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (46 loc) · 1.34 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
'Use strict'
const express = require('express');
const app = express();
const passport = require('passport');
const mongoose = require('mongoose');
require('dotenv').config()
const port = process.env.PORT
const session = require('express-session');
require('./config/passport')(passport)
app.use(require('serve-static')('./public'));
app.use(require('cookie-parser')());
app.use(require('body-parser').urlencoded({
extended: true
}));
app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: true,
cookie: {
secure: false
}
}))
app.use(passport.initialize());
app.use(passport.session());
app.set('views', './views');
app.set('view engine', 'ejs');
if (process.env.ENV == "p" || process.env.ENV == "production") {
const main = require('./routes/main')
app.use('/', main);
const internalApi = require('./routes/api/internal')
app.use('/api', internalApi);
const user = require('./routes/user')
app.use('/', user);
} else {
const development = require('./routes/development')
app.use('/', development);
}
mongoose.connect(process.env.MONGO, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false
});
app.listen(port, function () {
console.log(process.env.NAME + ' is live at: http://localhost:' + port);
});