]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/node-gyp/test/simple-proxy.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / node-gyp / test / simple-proxy.js
1 var http = require('http')
2   , https = require('https')
3   , server = http.createServer(handler)
4   , port = +process.argv[2]
5   , prefix = process.argv[3]
6   , upstream = process.argv[4]
7   , calls = 0
8
9 server.listen(port)
10
11 function handler (req, res) {
12   if (req.url.indexOf(prefix) != 0)
13     throw new Error('request url [' + req.url + '] does not start with [' + prefix + ']')
14
15   var upstreamUrl = upstream + req.url.substring(prefix.length)
16   console.log(req.url + ' -> ' + upstreamUrl)
17   https.get(upstreamUrl, function (ures) {
18     ures.on('end', function () {
19       if (++calls == 2)
20         server.close()
21     })
22     ures.pipe(res)
23   })
24 }