mirror of
https://github.com/electron/node-gyp.git
synced 2025-08-15 12:58:19 +02:00

In addition: * moved module.exports to the bottom * no single-line if statements * no if statements without a { * const for requires * array declarations get spaces inside [ ] * 'use strict' in all .js files PR-URL: https://github.com/nodejs/node-gyp/pull/1794 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: João Reis <reis@janeasystems.com>
27 lines
641 B
JavaScript
27 lines
641 B
JavaScript
'use strict'
|
|
|
|
const http = require('http')
|
|
const https = require('https')
|
|
const server = http.createServer(handler)
|
|
const port = +process.argv[2]
|
|
const prefix = process.argv[3]
|
|
const upstream = process.argv[4]
|
|
var 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)
|
|
https.get(upstreamUrl, function (ures) {
|
|
ures.on('end', function () {
|
|
if (++calls === 2) {
|
|
server.close()
|
|
}
|
|
})
|
|
ures.pipe(res)
|
|
})
|
|
}
|