-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
26 lines (20 loc) · 655 Bytes
/
Copy pathapp.js
File metadata and controls
26 lines (20 loc) · 655 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
const express = require("express");
const cors = require("cors");
const contactsRouter = require("./app/routes/contact.route");
const ApiError = require("./app/api-error");
const app = express();
app.use(cors());
app.use(express.json());
app.use("/api/contacts", contactsRouter);
app.use((req, res, next) => {
return next(new ApiError(404, "Resource not found"));
});
app.use((err, req, res, next) => {
return res.status(err.statusCode || 500).json({
message: err.message || "Internal Server Error",
});
});
app.get("/", (req, res) => {
res.json({ message: "Welcome to contact book application." });
});
module.exports = app;