-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
63 lines (51 loc) · 1.59 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
61
62
63
const express = require("express");
const path = require("path");
const PORT = process.env.PORT || 3001;
const app = express();
const morgan = require("morgan");
const axios = require("axios");
const bodyParser = require("body-parser");
const session = require("express-session");
const cookieParser = require("cookie-parser");
const passport = require("./passport/localStrategy");
//const passport = require('passport')
//local files
// const sequelize = require("./config/database");
const db = require("./models");
//req package to hide environment variables
require("dotenv").config();
// set morgan to log info about our requests for development use.
app.use(morgan("dev"));
// initialize body-parser to parse incoming parameters requests to req.body
app.use(bodyParser.urlencoded({ extended: true }));
// Define middleware here
app.use(express.json());
// Serve up static assets (usually on heroku)
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
}
app.use(cookieParser());
app.use(
session({
key: 'user_sid',
secret: process.env.SECRET,
resave: false,
saveUninitialized: false,
cookie: {
expires: 600000
}
})
);
app.use(passport.initialize());
app.use(passport.session());
// Define API routes here
require("./routes/api/api-routes")(app);
require("./routes/api/users-routes")(app);
app.get("*", function(req, res) {
res.sendFile(path.join(__dirname, "./client/build/index.html"));
});
db.sequelize.sync({ force: false }).then(() => {
app.listen(PORT, () => {
console.log(`🌎 ==> API server now on port ${PORT}!`);
});
});