Skip to content

Commit

Permalink
Update corsproxy
Browse files Browse the repository at this point in the history
  • Loading branch information
tehelsper authored Jun 6, 2020
1 parent b39b93c commit e4b6b61
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions bin/corsproxy
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var loggerOptions = require('../lib/logger-options')
var server = new Hapi.Server({})
var port = parseInt(process.env.CORSPROXY_PORT || process.env.PORT || 1337, 10)
var host = (process.env.CORSPROXY_HOST || 'localhost');
var target = (process.env.CORSPROXY_TARGET || null);
var maxPayload = parseInt(process.env.CORSPROXY_MAX_PAYLOAD || 1048576, 10)
var proxy = server.connection({ port: port, labels: ['proxy'], host: host})

Expand Down Expand Up @@ -37,8 +38,13 @@ proxy.route({
proxy: {
passThrough: true,
mapUri: function (request, callback) {
request.host = 'localhost:8332'
request.path = request.path.substr(request.params.host.length + 1)
if (target) {
request.host = target
request.path = '/'
} else {
request.host = request.params.host
request.path = request.path.substr(request.params.host.length + 1)
}
request.headers['host'] = request.host
var query = request.url.search ? request.url.search : ''
console.log('proxy to http://' + request.host + request.path)
Expand Down

0 comments on commit e4b6b61

Please sign in to comment.