Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • N node-http-proxy
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 482
    • Issues 482
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 102
    • Merge requests 102
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • http ... PARTY!
  • node-http-proxy
  • Issues
  • #120
Closed
Open
Issue created Sep 30, 2011 by Administrator@rootContributor

Router proxy means no proxyError :(

Created by: temsa

I have multiple host possible for my target, as I can have several stateless servers behind (for the moment, just 2).

I'd like, if ever the proxy request encounters an error (like ECONNREFUSED), to be able to redirect to another host. I couldn't make it work because I would need both:

  • Router based proxy
  • connect middlewares
  • 'proxyError' event to be thrown by my server.proxy.on('proxyError')

The latter is never emitted in this configuration.

(I'd also need for hang up errors a target connection timeout to be sent so I can dispatch the request to another server in this case).

Try this script (adapted from 2 examples), proxyError is never emitted :

var util = require('util'),
    colors = require('colors'),
    http = require('http'),
    httpProxy = require('http-proxy');

var server = httpProxy.createServer({
  router: {
    'localhost': 'localhost:9000'
  }
})
server.proxy.on('proxyError', function (err, req, res) {
  console.log('error'.red);
  res.writeHead(500, {
    'Content-Type': 'text/plain'
  });

  res.end('Something went wrong. And we are reporting a custom error message.');
});
server.listen(8001);
util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8001 '.yellow + 'with proxy table'.magenta.underline);
Assignee
Assign to
Time tracking