If you need some filters, just add a filters array property which contains your filters in filters/ folder to the handle function like this:

exports.get=function(req,res,next){

res.send(200,'Simple getting.');

};

// add filters

exports.get.filters=['authorization'];

Also you could define other HTTP methods handlers, but make sure in one file each URL! Example in controllers/user.js:

exports.get=function(req,res,next){

User.find({where:req.query.name}).success(function(user){

res.send(200, user);

});

};

exports.put=function(req,res,next){

User.create(req.body).success(function(user){

res.send(201,user.id);

});

};

// You can also define `post` and `delete` handlers.

// ...

If you want all methods to be process in only one controller(something not RESTful), just make exports to be the handle function:

module.exports = function (req, res, next) {

// all your process

};

Notice

Rainbow controllers only design for tranditional URL form like /path?query=value but not like /path/user/:id yet.

In rich Ajax apps tranditional URL form could be more useful. However, Rainbow may consider param form URL in future versions.

Filters

Make sure the filters you need had been defined in filters/ folder (could be changed) as same module name, because them will be required when initilizing. Here authorization.js is a example for intecepting by non-authenticated user before GEThttp://yourapp:6060/something:

module.exports=function(req,res,next){

console.log('processing authorization...');

var session =req.session;

if(session.userId){

console.log('user(%d) in session',session.userId);

next();

}else{

console.log('out of session');

// Async filter is ok with express!

db.User.find().success(function(user){

if(!user){

res.send(403);

res.end();

}

});

}

};

You could see filters is as same as a origin router in Express, just be put together in filters/ folder to be interceptors like in Java SSH.

Change default path

Controllers and filters default path could be changed by passing a path config object to route function when initializing: