-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
43 lines (34 loc) · 1.04 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
const express = require("express");
const bodyParser = require("body-parser");
const HttpError = require("./errors/http-error");
const NotFoundError = require("./errors/not-found");
const app = express();
const courselistRouter = require("./controllers/courselist-controller");
const articleRouter = require("./controllers/article-controller");
const errorRouter = require("./controllers/error-controller");
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// app.get('/', (req, res, next) => {
// res.status(200)
// })
app.use("/course-lists", courselistRouter);
app.use("/course-lists/articles", articleRouter);
app.use("/errors", errorRouter);
app.use((req, res, next) => {
return next(new NotFoundError());
});
app.use((err, req, res, next) => {
if (!(err instanceof HttpError)) {
err = new HttpError(err.message);
}
res.status(err.statusCode);
res.json({
error: err
});
});
if (!module.parent) {
app.listen(3000, () => {
console.log("Server launched on port 3000");
});
}
module.exports = app;