Created
February 16, 2016 20:29
-
-
Save myhrvold/0a88fa0331cc27b88c05 to your computer and use it in GitHub Desktop.
Handle-or-Forward Pattern Example for Ringpop
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
module.exports = function handleOrForward(ringpop, key, req, res, arg2, arg3, handle) { | |
var dest = ringpop.lookup(key); | |
if (dest === ringpop.whoami()) { | |
// Handle request on local node | |
handle(ringpop, key, res, arg2, arg3); | |
return; | |
} | |
// Forward request | |
var channel = ringpop.channel; | |
var peer = channel.peers.add(dest); | |
var outreq = new RelayRequest(channel, peer, req, function buildRes(options) { | |
res.headers = options.headers; | |
res.code = options.code; | |
res.ok = options.ok; | |
return res; | |
}); | |
outreq.createOutRequest(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment