Blame view

node_modules/jayson/examples/method_routing/server.js 525 Bytes
f7563de62   Palak Handa   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  var jayson = require(__dirname + '/../..');
  var format = require('util').format;
  
  var methods = {
    add: function(a, b, callback) {
      callback(null, a + b);
    }
  };
  
  var server = jayson.server(methods, {
    router: function(method) {
      // regular by-name routing first
      if(typeof(this._methods[method]) === 'function') return this._methods[method];
      if(method === 'add_2') {
        var fn = server.getMethod('add').getHandler();
        return jayson.Method(fn.bind(null, 2));
      }
    }
  });
  
  server.http().listen(3000);