-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
38 lines (34 loc) · 1.17 KB
/
server.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
const express = require("express");
const cors = require("cors");
const config = require("./config/config.js");
require('./config/db.js')
const topProductsRoute = require("./routes/topProductsRoute.js");
const newProductsRoute = require("./routes/newProductsRoute.js");
const orderRoute = require("./routes/ordersRoute.js");
const paymentSuccessRoute = require("./routes/paymentSuccessRoute.js");
const paymentFailRoute = require("./routes/paymentFailRoute.js")
const app = express();
app.use(express.urlencoded({extended:true}));
app.use(express.json());
app.use(cors());
app.use("/api", topProductsRoute);
app.use("/api/new", newProductsRoute);
app.use("/api", orderRoute);
app.use(paymentSuccessRoute);
app.use(paymentFailRoute);
// home route
app.get("/", (req, res)=>{
res.status(200).json({message : "Server is ready"})
})
// not found
app.use((req, res, next)=>{
res.status(200).json({message : "This url is not found"})
})
// server error
app.use((err, req, res, next)=>{
res.status(200).json({message : "Server something broke"})
})
const PORT = config.app.port;
app.listen(PORT, ()=>{
console.log(`Server is running successfully at http://localhost:${PORT}`);
})