-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (38 loc) · 1.1 KB
/
index.js
File metadata and controls
47 lines (38 loc) · 1.1 KB
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
const http = require('http');
const express = require('express');
const bodyParser = require("body-parser");
const app = express();
const cors = require('cors');
const session = require('express-session');
const MongoStore = require('connect-mongo')(session);
const db = require('./db');
app.use(cors({
origin: ['http://localhost:3000'],
methods: ['GET', 'POST', 'OPTIONS', 'DELETE', 'PUT'],
credentials: true
}));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.set('trust proxy', true);
app.use(session({
secret: 'work hard',
resave: true,
saveUninitialized: true,
cookie: {
secure: false,
maxAge: 24 * 60 * 60 * 1000,
},
store: new MongoStore({
mongooseConnection: db.connection
})
}));
require('express-async-errors');
require('./routes/routes')(app);
if (process.env.NODE_ENV === 'production') {
app.use(express.static('frontend/build'));
const path = require('path');
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'frontend', 'build', 'index.html'))
})
}
http.createServer(app).listen(process.env.PORT || 8000);