Created
October 3, 2013 14:51
-
-
Save rosshadden/6811117 to your computer and use it in GitHub Desktop.
Controller syntax experimenting for Cornerstone.
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
var services = app.util.loader.dirSync("services"); | |
var routes = { | |
"/"(req, res, next) { | |
// Render the view found at /views/index.html. | |
res.view("index"); | |
}, | |
"/test": { | |
get(req, res, next) { | |
res.json("test"); | |
}, | |
post(req, res, next) { | |
res.json("posted test!"); | |
} | |
}, | |
"/multiple": [ | |
// Starts with some verb-specific actions. | |
{ | |
get(req, res, next) { | |
log(req.method, "This should be hit, but not respond."); | |
next(); | |
}, | |
post(req, res, next) { | |
log(req.method, "POST success!"); | |
res.json("POST success!"); | |
} | |
}, | |
// Next hits an array of actions. | |
[ | |
(req, res, next) => { | |
log(req.method, "This should be hit, but not respond."); | |
next("route"); | |
}, | |
(req, res) => { | |
log(req.method, "This should be skipped."); | |
res.send("This should be skipped."); | |
} | |
], | |
// Last is a catch-all singular action. | |
(req, res, next) => { | |
log(req.method, "This should catch EVERYTHING else."); | |
res.send("This should catch EVERYTHING else."); | |
} | |
] | |
}; | |
module.exports = routes; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment