Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

strongloop / node-foreman / 230

8 May 2016 - 19:54 coverage: 88.64%. First build
230

Pull #117

travis-ci

8bd1dd86bbf8705a5a702b86a2f3a390?size=18&default=identiconrmg
proxy: add tests for multi-proxy behaviour

The test setup is based on the behaviour described in #93, but with the
required modifications to support testing without using any fixed ports.
Pull Request #117: WIP: Upgrade all outdated dependencies

43 of 51 new or added lines in 6 files covered. (84.31%)

554 of 625 relevant lines covered (88.64%)

92.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.1
/proxy.js
1
// Copyright IBM Corp. 2012,2016. All Rights Reserved.
2
// Node module: foreman
3
// This file is licensed under the MIT License.
4
// License text available at https://opensource.org/licenses/MIT
5

6
var fs      = require('fs');
15×
7
var http    = require('http');
15×
8
var https   = require('https');
15×
9
var htproxy = require('http-proxy');
15×
10

11
var port = parseInt(process.env.PORT);
15×
12

13
var upstream_host = process.env.UPSTREAM_HOST;
15×
14
var upstream_port = parseInt(process.env.UPSTREAM_PORT);
15×
15
var upstream_size = parseInt(process.env.UPSTREAM_SIZE);
15×
16
var sslCert       = process.env.SSL_CERT;
15×
17
var sslKey        = process.env.SSL_KEY;
15×
18
var sslPort       = parseInt(process.env.SSL_PORT);
15×
19

20
var addresses = [];
15×
21
for(var i = 0; i < upstream_size; i++) {
15×
22
  addresses.push({
15×
23
    host: upstream_host,
24
    port: upstream_port + i,
25
    protocol: 'http',
26
  });
27
}
28

29
// Proxy
30
var proxy = htproxy.createProxyServer({
15×
31
  // Set the x-forwarded- headers, because apps often need them to make
32
  // decisions (such as about redirecting to SSL or a canonical host),
33
  // and proxies often do this for you in the real world.
34
  xfwd: true
35
});
36

37
// Hanle Error
38
proxy.on('error',function(err,req,res){
15×
NEW
39
  console.error("Proxy Error: ",err);
!
NEW
40
  res.writeHead(500);
!
NEW
41
  res.write("Upstream Proxy Error");
!
NEW
42
  res.end();
!
43
});
44

45
// Main HTTP Server
46
http.createServer(function (req, res) {
15×
47

48
  var target = addresses.shift();
10×
49

50
  proxy.web(req, res, {target: target});
10×
51

52
  addresses.push(target);
10×
53

54
}).listen(port, function() {
55
  process.send({http: this.address().port});
15×
56
});
57

58
if (sslCert && sslKey) {
15×
59
  https.createServer({
5×
60
      key: fs.readFileSync(sslKey),
61
      cert: fs.readFileSync(sslCert)
62
    },
63
    function (req, res) {
64

65
    var target = addresses.shift();
5×
66

67
    proxy.web(req, res, {target: target});
5×
68

69
    addresses.push(target);
5×
70

71
  }).listen(sslPort, function() {
72
    process.send({https: this.address().port});
5×
73
  });
74
}
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc