-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
51 lines (39 loc) · 1.16 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
45
46
47
48
49
50
51
const express = require('express');
require('dotenv').config();
const session = require("express-session");
const passport = require("passport");
var cors = require('cors');
const app = express();
const PORT = process.env.PORT || 4001;
app.use(cors());
const path = require('path');
app.use(express.static(path.join(__dirname, 'static')));
require("./config/passport");
// Session Config
const pgSession = require('connect-pg-simple')(session);
const pool = require('./models/database');
app.use(session({
store: new pgSession({
pool,
tableName : 'session'
}),
secret: process.env.SESSION_SECRET,
cookie: { maxAge: 300000000, secure: false },
saveUninitialized: false,
resave: false,
}));
// Passport Config
app.use(passport.initialize());
app.use(passport.session());
const apiRouter = require('./routes/api/v1');
app.use('/api/v1',apiRouter);
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'static', 'index.html'));
});
// This conditional is here for testing purposes:
if (!module.parent || process.env.FORCE_DEPLOY) {
app.listen(PORT, () => {
console.log(`Server is listening on port ${PORT}`);
});
}
module.exports = app;