Server Request for racer
Request data from racer server. Can be used with racer or derby
$ npm i racer-server-request
You need to connect plugin for Store
and Model
.
You will get store.serverRequest.register
and model.serverRequest
methods.
model.serverRequest
can be used only with model.fetch
.
var derby = require('derby');
derby.use(require('racer-server-request').storePlugin());
store = derby.createStore({
listen: server
});
/*
* You have `this.session` and `this.done()` context
*/
store.serverRequest.register('tumblrInfo', function(param1, param2) {
var done = this.done;
if (this.session.name === param1)
tumblr.get('/user/info', function(err, data) {
done(err, data);
});
else
done('Access denied', null);
});
var derby = require('derby');
derby.use(require('racer-server-request').modelPlugin());
var app = derby.createApp(module);
app.get('/', function(page, model, params, next) {
var serverRequest = model.serverRequest('tumblrInfo', 'param1', 'param2');
model.fetch(serverRequest, function(err, scopedInfo) {
model.ref('_tumblrInfo', scopedInfo);
page.render();
});
});
You need to install grunt command globally:
$ npm i -g grunt-cli
- Watch coffee:
$ grunt