Skip to content

Instantly share code, notes, and snippets.

@bradley
Created March 18, 2018 23:05
Show Gist options
  • Save bradley/7c73326263118acc4423ca2433cc0d91 to your computer and use it in GitHub Desktop.
Save bradley/7c73326263118acc4423ca2433cc0d91 to your computer and use it in GitHub Desktop.
Simple route handling express.
// In app.js
require("./config/routes")(app, passport);
// In /config/routes.js
module.exports = function(app, passport) {
[
"users",
"sessions",
"stories"
].forEach(function (routeName) {
require(path.resolve("api/controllers/api/v1/" + routeName))(app, passport);
});
app.use(app.router);
app.get("*", function(req, res) {
res.send(404);
});
};
// In api/controllers/api/v1/users.js
// ... controller functions, like #create ...
module.exports = function(app) {
app.post("/api/v1/users", create);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment