-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.js
More file actions
25 lines (19 loc) · 705 Bytes
/
proxy.js
File metadata and controls
25 lines (19 loc) · 705 Bytes
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
'use strict';
if (process.argv.length < 2) {
console.error('Usage: `node proxy.js PORT`');
return process.exit(1);
}
var httpProxy = require('http-proxy');
var apiURL = 'https://www.bitmex.com';
var port = process.argv[2];
var proxy = httpProxy.createProxyServer({});
var server = require('http').createServer(function(req, res) {
// API validates origin and referer to prevent certain types of csrf attacks, so delete them
delete req.headers['origin'];
delete req.headers['referer'];
res.setHeader('Access-Control-Allow-Origin', '*');
req.url = '/api/v1' + req.url;
proxy.web(req, res, { target: apiURL });
});
server.listen(port);
console.log('Started BitMEX proxy on port', port);