-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (39 loc) · 1.17 KB
/
index.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
const express = require("express");
const mongoose = require("mongoose");
const app = express();
var cors = require("cors");
var morgan = require("morgan");
const productsRoute = require("./src/routes/productsRoute");
const userRoute = require("./src/routes/userRoute");
const chatRoute = require("./src/routes/chatRoutes");
require("dotenv").config();
app.use(cors());
app.use(express.json());
app.use(morgan("dev"));
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
}
mongoose
.connect(process.env.MONGO_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("Database connected!"))
.catch((err) => console.log(err));
// APIS
app.get("/", (req, res) => {
res.send("RETRO APIS");
});
// routes -----------------------------
app.use("/api/products", productsRoute);
app.use("/api/user", userRoute);
app.use("/api/chat", chatRoute);
// routes -----------------------------
app.get("*", (request, response) => {
response.sendFile(path.join(__dirname, "client/build", "index.html"));
});
// APIS
PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
console.log(`Our app is running on port ${PORT}`);
});