forked from pavansolapure/opencodez-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
35 lines (28 loc) · 765 Bytes
/
app.js
File metadata and controls
35 lines (28 loc) · 765 Bytes
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
import express from "express";
import bodyparser from "body-parser";
import cors from "cors";
import products from "./api/products";
import orders from "./api/orders";
const app = express();
app.use(cors());
app.use(bodyparser.json());
app.use(bodyparser.urlencoded({extended:false}));
app.use("/products",products);
app.use("/orders",orders);
//if we are here then the specified request is not found
app.use((req,res,next)=> {
const err = new Error("Not Found");
err.status = 404;
next(err);
});
//all other requests are not implemented.
app.use((err,req, res, next) => {
res.status(err.status || 501);
res.json({
error: {
code: err.status || 501,
message: err.message
}
});
});
module.exports = app;