-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (54 loc) · 1.58 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
59
60
61
62
63
64
const express = require('express');
const app = express();
const passport = require('passport');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const cookieSession = require('cookie-session');
const cookieParser = require('cookie-parser');
const requestLanguage = require('express-request-language');
const keys = require('./config/keys');
//Connecting Mongoose --> Don't change the order. userSchema should be called before passport.js.
require('./models/User');
require('./models/Pro');
mongoose.connect(keys.mongoURI);
//Connect bodyParser
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
//Connecting Passport
require('./services/passport');
//Set up cookies for Authentication
app.use(
cookieSession({
//Cookie lasts for 30 days
maxAge: 30 * 24 * 60 * 60 * 1000,
keys: [keys.cookieKey],
})
);
app.use(passport.initialize());
app.use(passport.session());
//Be able to read cookie
app.use(cookieParser());
//Set up cookies for language.
app.use(
requestLanguage({
languages: ['ko', 'en'],
cookie: {
name: 'language',
options: { maxAge: 365 * 24 * 3600 * 1000 },
},
})
);
//Routes
require('./routes/authRoutes')(app);
require('./routes/proRoutes')(app);
if (['production', 'ci'].includes(process.env.NODE_ENV)) {
app.use(express.static('client/build'));
const path = require('path');
app.get('*', (req, res) => {
res.sendFile(path.resolve('client', 'build', 'index.html'));
});
}
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
console.log(`Listening on port`, PORT);
});