Archived
1
0
This repository has been archived on 2022-11-26. You can view files and clone it, but cannot push or open issues or pull requests.

27 lines
587 B
JavaScript
Raw Normal View History

2022-06-03 00:29:39 +03:00
const express = require("express");
const bodyParser = require("body-parser");
const routes = {
lessons: require("./routes/lessons"),
};
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
function makeHandlerAwareOfAsyncErrors(handler) {
return async function (req, res, next) {
try {
await handler(req, res);
} catch (error) {
next(error);
}
};
}
app.get("/", makeHandlerAwareOfAsyncErrors(routes.lessons.getAll));
app.post("/lessons", makeHandlerAwareOfAsyncErrors(routes.lessons.create));
module.exports = app;