Skip to content

Instantly share code, notes, and snippets.

@jasonpincin
Last active August 29, 2015 13:57
Show Gist options
  • Save jasonpincin/9613781 to your computer and use it in GitHub Desktop.
Save jasonpincin/9613781 to your computer and use it in GitHub Desktop.
rpc server using dnode, shoe, node-static
var http = require('http')
var shoe = require('shoe')
var dnode = require('dnode')
var static = require('node-static')
var content = new static.Server(__dirname+'/static')
var server = http.createServer(content.serve.bind(content))
var socket = shoe(function (connection) {
// expose two methods: getTime and square
var api = dnode({
getTime: function (cb) {
cb(null, new Date())
},
square: function (n, cb) {
if (typeof n !== 'number') return cb(new Error('arg 1 must be a number'))
cb(null, n*n)
}
})
connection.pipe(api).pipe(connection)
})
socket.install(server, '/socket')
server.listen(8080)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment