Skip to content

Instantly share code, notes, and snippets.

@lexfrl
Created June 11, 2015 11:30
Show Gist options
  • Save lexfrl/3b5ea00ad3f127dc7a8e to your computer and use it in GitHub Desktop.
Save lexfrl/3b5ea00ad3f127dc7a8e to your computer and use it in GitHub Desktop.
server.use("/api", (req, res, next) => {
let route = router.match(req.url);
let service = null;
try {
service = require("./api/" + route.name.replace(".", "-"));
} catch (e) {
console.log(e.message);
res.status(404).send("Not Found");
return;
}
if(!service) {
res.status(404).send("Not Found");
return;
}
let { method } = req;
if (!service[method]) {
res.status(405).send("Method not allowed");
return;
} else {
service[method](route, req, res).then((result) => {
res.status(200).send(result);
return;
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment