-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
52 lines (41 loc) · 1.3 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
require("dotenv").config();
const express = require("express");
const routes = require("./routes");
const app = express();
const PORT = process.env.PORT || 3001;
const db = require("./models");
const passport = require("passport");
const session = require("express-session");
app.use(
session({
secret: "keyboard cat",
resave: true,
saveUninitialized: true
})
); // session secret
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
// Define middleware here
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
//(passport needs to be on end to recognize local strategy, idk why but is so)
require("./config/Passport/passport.js")(passport)
// Serve up static assets (usually on heroku)
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
}
// Add routes, both API and view
app.use(routes);
//true drops tables, false creates if not extant
var syncOptions = { force: false };
// If running a test, set syncOptions.force to true!
// clearing the `testdb`
if (process.env.NODE_ENV === "test") {
syncOptions.force = true;
}
// Start the API server
db.sequelize.sync(syncOptions).then(function() {
app.listen(PORT, function() {
console.log("App listening on PORT " + PORT);
});
});