-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (36 loc) · 1.19 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
const express = require('express');
const passport = require('passport');
const cors = require('cors');
require('dotenv').config();
const { connectToDb } = require('./utils/db');
const { errorHandler, notFound } = require('./middlewares');
const cookieParser = require('cookie-parser');
const path = require('path');
const PORT = process.env.PORT || 5000;
const app = express();
app.use(cookieParser());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(passport.initialize());
app.use(cors({ origin: true, credentials: true }));
require('./services/passportLocalStrategy');
require('./services/jwtStrategy');
app.use('/api', require('./routes'));
if (process.env.NODE_ENV === 'production') {
app.use(express.static(path.join(__dirname, '/client/build')));
app.use('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
} else {
app.get('/', (req, res) => {
res.json({ message: 'League Simulation :)' });
});
}
app.use(notFound);
app.use(errorHandler);
connectToDb()
.then(async _ => {
console.log('connected to db');
app.listen(PORT, () => console.log(`app listening on port ${PORT}!`));
})
.catch(e => console.log(e));