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
  • #843
Closed
Open
Issue created Jun 26, 2015 by Administrator@rootContributor

node-http-proxy XHR post call hanging

Created by: elankeeran

Create a simple express app and try to do proxy.

Proxy working fine when request is GET but it getting hang on post XHR call

var express = require('express');
var path = require('path');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var httpProxy = require('http-proxy');
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
var apiProxy = httpProxy.createProxyServer();
app.use(function(req, res,next){
    apiProxy.web(req, res, { target: 'http://localhost:9000' } );

});
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
  res.status(err.status || 500);
  res.render('error', {
    message: err.message,
    error: {}
  });
});

module.exports = app;

Googled and got this solution https://github.com/nodejitsu/node-http-proxy/issues/180

var restreamer = function (){
        return function (req, res, next) { //restreame
            req.removeAllListeners('data')
            req.removeAllListeners('end')
            next()
            process.nextTick(function () {
                if(req.body) {
                    req.emit('data', JSON.stringify(req.body))
                }
                req.emit('end')
            })
        }
    }

    app.use(restreamer());

but now application not hanging. I am getting response 404 not found. and getting below error

/Volumes/Data/nodejs/express-apps/myapp/node_modules/http-proxy/lib/http-proxy/index.js:119
    throw err;
          ^
Error: socket hang up
    at createHangUpError (_http_client.js:215:15)
    at Socket.socketOnEnd (_http_client.js:300:23)
    at Socket.emit (events.js:129:20)
    at _stream_readable.js:908:16
    at process._tickCallback (node.js:355:11)
Assignee
Assign to
Time tracking