Created
June 11, 2015 11:30
-
-
Save lexfrl/3b5ea00ad3f127dc7a8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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