Express http-proxy套接字关闭

时间:2019-05-03 20:57:47

标签: node.js express proxy node-http-proxy

我遇到一个问题,每当我使用http-proxy调用后端应用程序时,它都会返回错误。在过去的文章中,bodyParser引起了一些问题,但是当我删除bodyParser时,错误就包括了。我四处张望,却一无所获。

这是代码

var express = require('express');
var router = express.Router();

var http = require('http');
var httpProxy = require('http-proxy')

var proxyOptions = {
  host: "127.0.0.1",
  port: 8983
};
var proxy = httpProxy.createProxyServer(proxyOptions);

// It works excellent in GET request
router.get('/solr/*', function(req, res) {
  proxy.web(req, res, {
    target: 'http://' + proxyOptions.host + ':' + proxyOptions.port
  });
})

// the socket hang up in post request
router.post('/solr/*', function(req, res) {
  console.log('Post Request');
  proxy.web(req, res, {
    target: 'http://' + proxyOptions.host + ':' + proxyOptions.port
  });
})

这是错误:

/home/ubuntu/site/node_modules/http-proxy/lib/http-proxy/index.js:120
    throw err;
    ^

Error: socket hang up
    at createHangUpError (_http_client.js:331:15)
    at Socket.socketOnEnd (_http_client.js:423:23)
    at emitNone (events.js:111:20)
    at Socket.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

有人知道我该如何解决这个问题?我处于死胡同。

0 个答案:

没有答案