Last active
August 29, 2015 13:57
-
-
Save jasonpincin/9613781 to your computer and use it in GitHub Desktop.
rpc server using dnode, shoe, node-static
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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