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

strongloop / node-foreman / 224

2 May 2016 - 8:27 coverage: 88.78%. First build
224

Pull #117

travis-ci

8bd1dd86bbf8705a5a702b86a2f3a390?size=18&default=identiconrmg
improve Procfile parsing error messages
Pull Request #117: WIP: Upgrade all outdated dependencies

27 of 33 new or added lines in 5 files covered. (81.82%)

546 of 615 relevant lines covered (88.78%)

93.43 hits per line

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

87.1
/proxy.js
1
var fs      = require('fs');
10×
2
var http    = require('http');
10×
3
var https   = require('https');
10×
4
var htproxy = require('http-proxy');
10×
5

6
var port = parseInt(process.env.PORT);
10×
7

8
var upstream_host = process.env.UPSTREAM_HOST;
10×
9
var upstream_port = parseInt(process.env.UPSTREAM_PORT);
10×
10
var upstream_size = parseInt(process.env.UPSTREAM_SIZE);
10×
11
var sslCert       = process.env.SSL_CERT;
10×
12
var sslKey        = process.env.SSL_KEY;
10×
13
var sslPort       = parseInt(process.env.SSL_PORT);
10×
14

15
var addresses = [];
10×
16
for(var i = 0; i < upstream_size; i++) {
10×
17
  addresses.push({
10×
18
    host: upstream_host,
19
    port: upstream_port + i,
20
    protocol: 'http',
21
  });
22
}
23

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

32
// Hanle Error
33
proxy.on('error',function(err,req,res){
10×
NEW
34
  console.error("Proxy Error: ",err);
!
NEW
35
  res.writeHead(500);
!
NEW
36
  res.write("Upstream Proxy Error");
!
NEW
37
  res.end();
!
38
});
39

40
// Main HTTP Server
41
http.createServer(function (req, res) {
10×
42

43
  var target = addresses.shift();
5×
44

45
  proxy.web(req, res, {target: target});
5×
46

47
  addresses.push(target);
5×
48

49
}).listen(port, function() {
50
  process.send({http: this.address().port});
10×
51
});
52

53
if (sslCert && sslKey) {
10×
54
  https.createServer({
5×
55
      key: fs.readFileSync(sslKey),
56
      cert: fs.readFileSync(sslCert)
57
    },
58
    function (req, res) {
59

60
    var target = addresses.shift();
5×
61

62
    proxy.web(req, res, {target: target});
5×
63

64
    addresses.push(target);
5×
65

66
  }).listen(sslPort, function() {
67
    process.send({https: this.address().port});
5×
68
  });
69
}
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