source: trip-planner-front/node_modules/node-gyp/test/simple-proxy.js@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years 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.