-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
53 lines (46 loc) · 1.36 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
require('dotenv').config();
const express = require('express');
const session = require('express-session');
const path = require('path');
const pgSession = require('connect-pg-simple')(session);
const app = express();
const { db } = require('./db/db');
const cors = require('cors');
if (process.env.NODE_ENV !== 'production') {
app.use(
cors({
origin: 'http://localhost:3000',
credentials: true
})
);
}
app.disable('x-powered-by');
app.use(
session({
store: new pgSession({
pgPromise: db
}),
name: process.env.SESSION_NAME,
secret: process.env.SESSION_SECRET,
saveUninitialized: false,
resave: false,
cookie: {
maxAge: 30 * 24 * 60 * 60 * 1000,
sameSite: 'strict',
httpOnly: true,
secure: process.env.NODE_ENV === 'production' ? true : false
}
})
);
app.use(express.json());
app.use('/api/update', require('./routes/update'));
app.use('/api/load', require('./routes/load'));
app.use('/api/check-off', require('./routes/check-off'));
app.use('/api/delete', require('./routes/delete'));
app.use('/api/auth', require('./routes/auth'));
app.use(express.static('client/build'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server started on port ${PORT}`));