0

This is a small proxy program I wrote to test some case.

var httpProxy = require('http-proxy'),
    connect   = require('connect'),
    endpoint  = {
      host:   'googleeeeeee.com', // or IP address
      port:   80,
    },
    staticDir = 'public';

var proxy = new httpProxy.RoutingProxy();
var app = connect()
  .use(connect.logger('dev'))
  .use(function(req, res) {
      proxy.proxyRequest(req, res, endpoint);
      console.log("Respose is " + res.statusCode);
  })
  .use(connect.static(staticDir))
  .listen(80);
  console.log("Server started");

this uses
"http-proxy": "0.8.x" "connect": "2.3.x"

When I run this program and access it, the statusCode is 200 through the target URL does not exist. Any help much appreciated. This is in continuation with How to catch 404 errors using connect framework

Community
  • 1
  • 1
Nandish A
  • 1,645
  • 5
  • 26
  • 41

1 Answers1

0

This was solved by this code

Created a file called errorhandler.js

module.exports = function() {
        return function(req, res, next) {
                var end = res.end;
                res.end = function(chunk, encoding){
                        res.end = end;
                        res.end(chunk, encoding);
                        console.log("Reponse code is " + res.statusCode);

                };
                next();
        }
}

then included this in the middleware

var httpProxy = require('http-proxy'),
    connect   = require('connect'),
    endpoint  = {
      host:   'googleeeeeee.com', // or IP address
      port:   80,
    },
    staticDir = 'public';

var proxy = new httpProxy.RoutingProxy();
var app = connect()
  .use(require('./errorHandler').errorHandler())
  .use(connect.logger('dev'))
  .use(function(req, res) {
      proxy.proxyRequest(req, res, endpoint);
  })
  .use(connect.static(staticDir))
  .listen(80);
  console.log("Server started");
Nandish A
  • 1,645
  • 5
  • 26
  • 41