-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
65 lines (52 loc) · 1.64 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
64
65
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const passport = require('passport');
const LocalStrategy = require('passport-local').Strategy;
const session = require("express-session");
const bodyParser = require('body-parser');
const routes = require('./routes/');
const db = require("./models");
const auth = require('./utils/auth');
const app = express();
const PORT = process.env.PORT || 3001;
console.log(PORT)
passport.use(new LocalStrategy(auth.verify));
passport.serializeUser(auth.serializeUser);
passport.deserializeUser(auth.deserializeUser);
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
}
//For BodyParser
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(cors());
app.set("trust proxy", 1); // trust first proxy
const cookieSecure = process.env.NODE_ENV === "production";
app.use(
session({
secret: process.env.COOKIE_SECRET || "keyboard cat",
resave: false,
saveUninitialized: true,
cookie: { httpOnly: true, maxAge: 1000 * 60 * 5, secure: cookieSecure }
})
);
app.use(passport.initialize());
app.use(passport.session());
app.use(routes);
let syncOptions = { force: false };
// Serve up static assets (usually on heroku)
if(process.env.NODE_ENV === "test"){
syncOptions.force = false;
}
// app.post("/employees", (req, res) => {
// // console.log(req.json());
// res.status(100);
// })
// Start the API server
db.sequelize.sync(syncOptions).then( () => {
app.listen(PORT, function() {
console.log(`🌎 ==> API Server now listening on PORT ${PORT}!`);
});
});
module.exports = app;