Skip to content

Instantly share code, notes, and snippets.

@rosshadden
Created October 3, 2013 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rosshadden/6811117 to your computer and use it in GitHub Desktop.
Save rosshadden/6811117 to your computer and use it in GitHub Desktop.
Controller syntax experimenting for Cornerstone.
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