-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
50 lines (40 loc) · 1.11 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
// Variables
const express = require("express");
const logger = require("morgan");
const session = require("express-session");
const mongoose = require("mongoose");
const passport = require("./config/passport");
const PORT = process.env.PORT || 3001;
const db = require("./models");
const app = express();
// Use Express
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// Express Session
app.use(session({
secret: "secret",
saveUninitialized: true,
resave: true
}));
app.use(logger("dev"));
// Passport init
app.use(passport.initialize());
app.use(passport.session());
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
}
app.use(require("./routes/playlistRoute"));
app.use(require("./routes/userAuthRoute"));
// Connect to Database
mongoose.connect(process.env.MONGODB_URI || "mongodb://localhost/playlist",
{
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false
}
);
// Start Server
app.listen(PORT, () => {
console.log(`App running on port ${PORT}!`);
});