Skip to content

Instantly share code, notes, and snippets.

@erichocean
Last active December 20, 2015 19:28
Show Gist options
  • Save erichocean/6182953 to your computer and use it in GitHub Desktop.
Save erichocean/6182953 to your computer and use it in GitHub Desktop.
How to connect with a Racer client running on Node to a Racer server also running on Node. You also need to comment out everything in node_modules/racer/lib/Model/connection.server.js.
var racer = require('racer');
var BCSocket = require('browserchannel').BCSocket;
racer.Model.prototype._createSocket = function(bundle) {
var options = bundle.racerBrowserChannel;
var base = options.base || '/channel';
if (bundle.mount) base = bundle.mount + base;
base = 'http://localhost:3000' + base; /////////<====== Change this to the address and
///////// port of your Racer server.
return new BCSocket(base, options);
};
racer.init({
"queries": [],
"contexts": {
"root": {
"fetchedDocs": {},
"subscribedDocs": {},
"fetchedQueries": {},
"subscribedQueries": {}
}
},
"refs": [],
"refLists": [],
"fns": [],
"filters": [],
"collections": {},
"racerBrowserChannel": {
"reconnect": true,
"hostPrefixes": null,
"base": "/channel",
"keepAliveInterval": 20000,
"sessionTimeoutInterval": 30000,
"cors": null,
"headers": {
"Content-Type": "text/plain",
"Cache-Control": "no-cache, no-store, max-age=0, must-revalidate",
"Pragma": "no-cache",
"Expires": "Fri, 01 Jan 1990 00:00:00 GMT",
"X-Content-Type-Options": "nosniff"
}
}
});
racer.ready(function(model) {
model.subscribe('people.520053830ec8ce34cfe72ab7', function(err) {
if (err) throw err;
// Now you can do something with the document you subscribed to.
console.log(model.get('people.520053830ec8ce34cfe72ab7.name'));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment