Created
March 18, 2018 23:05
-
-
Save bradley/7c73326263118acc4423ca2433cc0d91 to your computer and use it in GitHub Desktop.
Simple route handling express.
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
// 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