-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Boris Filipov edited this page Aug 18, 2014
·
3 revisions
The organelle finds all files matched given pattern (usually using recursive search via /**/* pattern).
Those files are then expected to export a builder function which results in object having "route": handler properties. Depending on the file location all routes from the object with their corresponding handlers are mounted to the expressjs app prefixed with the urlized file path.
index.js files are special ones and will be mounted first before any sibling or inner files without their name included.
For example this directory tree:
- root
|- a.js
|- index.js
|- folder
|- _a.js
|- index.js
Will be mounted in the following order:
- index.js
- a.js
- folder/index.js
- folder/_a.js
And handlers from those files will be available mapped at the following urls:
- / -> index.js
- /a -> a.js
- /folder -> folder/index.js
- /folder/_a -> folder/_a.js
// context/routes/action.js
module.exports = function(){
return {
"GET": function(req, res, next) {
res.send("I'm GET action")
}
}
}
// open http://localhost:1337/action to see "I'm GET action" response
// context/routes/resources/update.js
module.exports = function(){
return {
"POST": function(req, res, next) {
res.send("I'm POST action of resources")
},
"DELETE": require("./my-implementation"),
"PUT /inner/path": function(){}
}
}
// POST to http://localhost:1337/resources/update to see response
// see "DELETE" and "PUT" methods has handlers too and their routes will be available respectively at
// DELETE http://localhost:1337/resources/update
// PUT http://localhost:1337/resources/update/inner/path