Skip to content

Instantly share code, notes, and snippets.

@awsp
Last active August 29, 2015 14:04
Show Gist options
  • Save awsp/e9b54e99283681cd0c21 to your computer and use it in GitHub Desktop.
Save awsp/e9b54e99283681cd0c21 to your computer and use it in GitHub Desktop.
// Server side, BarController
module.exports = {
foo: function (req, res) {
res.view('foo');
},
save: function (req, res) {
Bar.create({
name: 'bar'
}, function barCreated (err, bar) {
if (err) {
next(err);
}
else {
Bar.publishCreate(bar);
}
});
res.send(200);
},
subscribe: function (req, res) {
Bar.subscribe(req.socket);
res.send(200);
}
};
// Client
$(function() {
var socket = io.connect();
socket.on('connect', function () {
socket.get('/bar/subscribe');
socket.on('message', function (data) {
console.log(data);
});
});
$("body").on("click", "#submit-bar", function (e) {
socket.get('/bar/save');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment