forked from ThatGuyAtASU/Bucket-List
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
37 lines (26 loc) · 928 Bytes
/
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
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const user = require("./routes/api/user");
const items = require("./routes/api/items");
//Initialize App
const app = express();
//Body Parser Middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(express.static("client/build"));
//Connect to MongoDB
var MONGODB_URI = process.env.MONGODB_URI || "mongodb://localhost/bucketlistdb";
mongoose.connect(MONGODB_URI);
//Define API Routes
app.use("/api/user", user);
app.use("/api/items", items);
// Send every other request to the React app
// Define any API routes before this runs
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "./client/build/index.html"));
});
const PORT = process.env.PORT || 3001;
app.listen(PORT, () => {
console.log(`🌎 ==> API server now on port ${PORT}!`);
});