-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor for clarity, fix dist-url, add env var dist-url functionality
PR-URL: #711 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
- Loading branch information
Showing
7 changed files
with
305 additions
and
91 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
gyp/test | ||
node_modules | ||
test/.node-gyp |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var http = require('http') | ||
, https = require('https') | ||
, server = http.createServer(handler) | ||
, port = +process.argv[2] | ||
, prefix = process.argv[3] | ||
, upstream = process.argv[4] | ||
, calls = 0 | ||
|
||
server.listen(port) | ||
|
||
function handler (req, res) { | ||
if (req.url.indexOf(prefix) != 0) | ||
throw new Error('request url [' + req.url + '] does not start with [' + prefix + ']') | ||
|
||
var upstreamUrl = upstream + req.url.substring(prefix.length) | ||
console.log(req.url + ' -> ' + upstreamUrl) | ||
https.get(upstreamUrl, function (ures) { | ||
ures.on('end', function () { | ||
if (++calls == 2) | ||
server.close() | ||
}) | ||
ures.pipe(res) | ||
}) | ||
} |
Oops, something went wrong.