-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
35 lines (29 loc) · 809 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
const express = require("express");
const colors = require("colors");
const morgan = require("morgan");
const { conn } = require("./config/mongo");
const router = require("./routes/route");
const cors = require("cors");
require("dotenv").config();
const app = express();
app.use(morgan("dev"));
app.use(express.json());
const whiteList = ["http://localhost:3000"];
app.use(cors({ origin: whiteList }));
app.use("/api/v1", router);
app.get("/", (req, res) => {
res.redirect("api/v1/products");
});
conn();
const port = process.env.PORT || 8000;
app.listen(port, () => {
try {
console.log(
colors.blue(
`Server listening successfully on port http://localhost:${port}`
)
);
} catch (error) {
console.log(colors.red("Failed to listen on server port:", error));
}
});