-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
61 lines (40 loc) · 1.62 KB
/
server.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
require('dotenv').config();
require('./initDockerSecrets')();
const path = require('path');
const express = require('express');
const session = require('express-session');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const app = express();
const passport = require('passport');
// configuration ===============================================================
// connect to our database
require('./server/config/passport')(passport); // pass passport for configuration
app.use(require('helmet')());
// set up our express application
app.use(morgan('dev')); // log every request to the console
app.use(cookieParser()); // read cookies (needed for auth)
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
// required for passport
app.use(session({
secret: 'camelslikehorseshavefourlegs',
resave: true,
saveUninitialized: true
} )); // session secret
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(passport.authenticate('remember-me'));
app.use(express.static('client/build'));
// routes =====================================================================
require('./server/app/routes/index')(app, passport); // load our routes and pass in our app and fully configured passport
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, 'client/build/index.html'));
});
app.set('port', (process.env.API_PORT || 3002));
app.listen(app.get('port'), () => {
console.log(`Find the server at: http://localhost:${app.get('port')}/`); // eslint-disable-line no-console
});