forked from iij/yokozuna-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy.js
29 lines (25 loc) · 815 Bytes
/
proxy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
if (process.argv.length != 4) {
console.log('Usage: node proxy.js PORT RIAK_HOST:RIAK_PORT');
process.exit(1);
}
var port = parseInt(process.argv[2]);
var riak_server = {
host: process.argv[3].split(':')[0],
port: parseInt(process.argv[3].split(':')[1])
};
var http = require('http'),
static = require('node-static'),
httpProxy = require('http-proxy');
var fileServer = new static.Server('./');
var proxy = new httpProxy.RoutingProxy();
http.createServer(function(req, res) {
if (req.url.lastIndexOf('/search/', 0) == 0) {
proxy.proxyRequest(req, res, riak_server);
} else if (req.url.lastIndexOf('/buckets/', 0) == 0) {
proxy.proxyRequest(req, res, riak_server);
} else {
req.addListener('end', function() {
fileServer.serve(req, res);
}).resume();
}
}).listen(port);