simple.controller.example.js | |
---|---|
Convience hive.at(path) | var hive = require('hive');
var view = hive.view;
var redirect = hive.redirect;
var User = hive.models.User;
var Session = hive.models.Session;
var Users = hive.queries.Users; |
hive.at(context)context A | |
This will set the context of all following routes to | hive.at('/user') |
hive.get(route, [handler])context A | |
handler [optional] A handler can be a model, a query, or a | |
| .get('/all', Users)
.post('/new', User) |
Routes are implicitely bound to a view by their name. For example. | .get('/new')
.get('/login') |
hive.post(route, [handler])context A | |
handler [optional] A handler can be a model, a query, or a | |
| .post('/login', function(req, res) {
var model = new Session(req.body);
var result = {
model: model,
redirect: '/dashboard',
success: function() {
res.cookie('auth', model.get('auth'), {httpOnly: true});
}
};
return result;
}) |
This route will respond to | .at('/register')
.get('/', function () {
return redirect('/user/new');
})
.at('/dashboard')
.get('/', function(req, res) {
return view('user/dashboard.haml');
});
|