-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
49 lines (40 loc) · 1.34 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
const express = require("express");
const createError = require("http-errors");
const morgan = require("morgan");
require("dotenv").config();
const dbConnection = require("./config/DB");
const app = express();
app.use(express.json({ limit: "10mb" }));
app.use(express.urlencoded({ limit: "10mb", extended: false }));
app.use(morgan("dev"));
dbConnection();
app.get("/", async (req, res, next) => {
res.send({ message: "Awesome it works 🐻" });
});
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", process.env.CLIENT_URL);
res.setHeader("Access-Control-Allow-Methods", "GET, POST, DELETE,PUT");
res.setHeader(
"Access-Control-Allow-Headers",
"Content-Type",
"Authorization"
);
res.header("Access-Control-Allow-Credentials", true);
next();
});
app.use("/api/product", require("./routes/product.route"));
app.use("/api/marketPlace", require("./routes/supermarketPrice.route"));
app.use("/api/seeds", require("./routes/seed.route"));
app.use("/api/tools", require("./routes/tool.route"));
app.use((req, res, next) => {
next(createError.NotFound());
});
app.use((err, req, res, next) => {
res.status(err.status || 500);
res.send({
status: err.status || 500,
message: err.message,
});
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`🚀 @ http://localhost:${PORT}`));