Chungking
Controller for Connect and Express (Node.js / Express.js / Connect.js). Name comes from Chungking Express.
Install
npm install chungking
Usage
Set up a Users controller
// users.jsvar BaseController = BaseController; var Users = BaseController; moduleexports = Users;
Call the controller from your request handler:
// app.jsvar Users = ; // ... app;
That's it!
Restricting beforeFilters to only specific actions
this { console; //authentication code here...} // restrict to only some actionsthis; // execute for all actions except listed actionsthis;
Tired of writing this.req, this.res and this.next?
You can optionally get them as params to your beforeFilters and actions.
this;
Extending controllers
You can also extend controllers.
Application controller:
// application.jsvar BaseController = BaseController; var Application = BaseController; moduleexports = Application;
Users controller which extends the Application controller:
// users.jsvar Application = ; var Users = Application;
TODO
Rethink how inheritance works. Maybe child controllers should not inherit before filters and actions.
Refactor the way inheritance is done. Maybe use utils.inherit from node.js http://nodejs.org/api/util.html#util_util_inherits_constructor_superconstructor.