-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
77 lines (57 loc) · 1.75 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const express = require('express');
const session = require('express-session');
let passport = require('passport');
let routes = require('./routes');
const connection = require('./config/database');
const cors = require('cors');
// Package documentation - https://www.npmjs.com/package/connect-mongo
const MongoStore = require('connect-mongo')(session);
/**
* -------------- GENERAL SETUP ----------------
*/
// Gives us access to variables set in the .env file via `process.env.VARIABLE_NAME` syntax
require('dotenv').config();
// Create the Express application
let app = express();
app.use(express.json());
app.use(express.urlencoded({extended: true}));
/**
* -------------- SESSION SETUP ----------------
*/
const sessionStore = new MongoStore({ mongooseConnection: connection, collection: 'sessions' });
app.use(session({
secret: process.env.SECRET,
resave: false,
saveUninitialized: true,
store: sessionStore,
cookie: {
maxAge: 1000 * 60 * 60 * 24 // Equals 1 day (1 day * 24 hr/1 day * 60 min/1 hr * 60 sec/1 min * 1000 ms / 1 sec)
}
}));
/**
* -------------- PASSPORT AUTHENTICATION ----------------
*/
// Need to require the entire Passport config module so app.js knows about it
require('./config/passport');
app.use(passport.initialize());
app.use(passport.session());
/*app.use((req, res, next) => {
console.log(req.session);
console.log(req.user);
next();
});*/
/**
* -------------- ROUTES ----------------
*/
// Imports all the routes from ./routes/index.js
app.use(routes);
/**
* -------------- SERVER ----------------
*/
app.use(cors({
origin: "http://localhost:3001",
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
credentials: true
}));
// Server listens on http://localhost:3000
app.listen(3000);