-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
63 lines (52 loc) · 1.66 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 mongoose = require("mongoose");
const passport = require("passport");
const users = require("./routes/api/users");
const projects = require("./routes/api/projects");
const logs = require("./routes/api/logs");
const clients = require("./routes/api/clients");
const app = express();
const PORT = process.env.PORT || 4000;
// Define middleware here
app.use(express.urlencoded({
extended: true
}));
app.use(express.json());
// Serve up static assets (usually on heroku)
if (process.env.NODE_ENV === "production") {
// Set static folder
app.use(express.static("client/build"));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
}
// API Routes
app.use("/api/users", users);
app.use("/api/projects", projects);
app.use("/api/clients", clients);
app.use("/api/logs", logs);
// Database Setup for Prod Env
// DB Config
// const db = process.env.mongoURI;
// // // Connect to MongoDB
// mongoose
// .connect(
// db || "mongodb://localhost/timekeeperapp", {
// useNewUrlParser: true
// }
// )
// .then(() => console.log("MongoDB successfully connected"))
// .catch(err => console.log(err));
// Passport middleware
app.use(passport.initialize());
// Passport config
require("./config/passport")(passport);
// // Connect to the Mongo DB
mongoose.connect(process.env.MONGODB_URI || "mongodb://localhost/timekeeperapp")
.then(() => console.log("MongoDB successfully connected"))
.catch(err => console.log(err));
// Start the API server
app.listen(PORT, function () {
console.log(`🌎 ==> Server listening on PORT ${PORT}!`);
});