forked from morgan-b/rubber-duckies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (39 loc) · 1.25 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
const express = require("express");
const path = require("path");
const PORT = process.env.PORT || 3001;
const app = express();
const session = require("express-session");
const models = require("./models");
const routes = require("./controllers");
const sequelize = require("./config/connection");
const SequelizeStore = require("connect-session-sequelize")(session.Store);
// Serve up static assets (usually on heroku)
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
// app.set('trust proxy', 1) // trust first proxy
// sess.cookie.secure = true // serve secure cookies
}
const sess = {
secret: "Super secret secret",
cookie: {
//Session expiration is set to 60 minutes
expires: 60 * 60 * 1000,
},
resave: false,
saveUninitialized: true,
store: new SequelizeStore({
db: sequelize,
}),
};
app.use(session(sess));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// Send every request to the React app
// Define any API routes before this runs
app.use(routes);
app.get("/*", function (req, res) {
res.sendFile(path.join(__dirname, "/client/build/index.html"));
});
sequelize.sync({ force: false }).then(() => {
app.listen(PORT, () => console.log("Now listening"));
});