source: node_modules/node-gyp/test/simple-proxy.js@ 81bc7da

finki-main main
Last change on this file since 81bc7da was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago

Initial commit

  • Property mode set to 100644
File size: 641 bytes
Line 
1'use strict'
2
3const http = require('http')
4const https = require('https')
5const server = http.createServer(handler)
6const port = +process.argv[2]
7const prefix = process.argv[3]
8const upstream = process.argv[4]
9var calls = 0
10
11server.listen(port)
12
13function handler (req, res) {
14 if (req.url.indexOf(prefix) !== 0) {
15 throw new Error('request url [' + req.url + '] does not start with [' + prefix + ']')
16 }
17
18 var upstreamUrl = upstream + req.url.substring(prefix.length)
19 https.get(upstreamUrl, function (ures) {
20 ures.on('end', function () {
21 if (++calls === 2) {
22 server.close()
23 }
24 })
25 ures.pipe(res)
26 })
27}
Note: See TracBrowser for help on using the repository browser.