forked from rmanosalvas/Date_Match
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
60 lines (55 loc) · 1.82 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
54
55
56
57
58
59
60
const path = require('path');
const express = require('express');
const db = require('./models'); //Requiring models folder to set up sequelize
const routes = require('./routes'); //Requiring routes folder that can hold api and html routes
const app = express();
const passport = require("./config/passport"); // Requiring passport
const session = require("express-session"); // Requiring session for passport
const PORT = process.env.PORT || 5000;
// passport config
app.use(session({
secret: "partylater",
resave: true,
saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());
// Configure body parser for AJAX requests
app.use(express.urlencoded({
extended: true
}));
app.use(express.json());
// Serve up static assets
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'));
}
// Html Routes
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
app.get('/dashboard', function (req, res) {
res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
app.get('/matches', function (req, res) {
res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
app.get('/community', function (req, res) {
res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
app.get('/profile', function (req, res) {
res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
app.get('/password', function (req, res) {
res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
//Api Routes The is a index file the will direct routes traffic in the folder
app.use(routes);
//{ force: false } to not overwrite DB each app load
//{ force: true } to overwrite DB each app load
db.sequelize.sync({
force: false
}).then(() => {
app.listen(PORT, () => {
console.log(`Listening on PORT ${PORT}`);
});
});