-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
37 lines (27 loc) · 936 Bytes
/
app.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 cors = require("cors");
const path = require("path");
require("dotenv").config();
const routes = require("./server/routes");
const PORT = process.env.PORT || 9000;
mongoose
.connect(process.env.MONGO_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then((success) => console.log("Database connected succesfully!"))
.catch((err) => console.log("error connecting to database", err));
const app = express();
app.use(express.json());
app.use(cors());
app.use(routes);
app.get("/test", (req, res) => {
res.send("app is running just fine");
});
app.use(express.static(__dirname));
app.use(express.static(path.join(__dirname, "client/build")));
app.get("/*", function (req, res) {
res.sendFile(path.join(__dirname, "client/build", "index.html"));
});
app.listen(PORT, () => console.log(`app is running on port ${PORT}`));