-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (24 loc) · 889 Bytes
/
index.js
File metadata and controls
31 lines (24 loc) · 889 Bytes
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
const bodyParser = require("body-parser");
const express = require("express");
const mongoose = require("mongoose");
const app = express();
const path = require("path");
require("dotenv").config();
const db = require("./config/keys");
const landing = require("./routes/api/landing");
// Connect to MongoDB.
mongoose
.connect(db.mongoURI)
.then(() => console.log("MongoDB connected"))
.catch(err => console.log(err));
app.use(bodyParser.json());
// Home page.
app.use("/api/", landing);
// Serve static files from the React frontend app
app.use(express.static(path.join(__dirname, "frontend/build")));
// Anything that doesn't match the above, send back index.html
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname + "/frontend/build/index.html"));
});
const port = process.env.PORT || 8000;
app.listen(port, () => console.log(`Server running on port ${port}`));