node-http-proxy POST请求超时

卡尔提克

我对POST请求使用node-http-proxy,如下所示:

route.js
---------

var express = require('express');
var httpProxy = require('http-proxy');
var bodyParser = require('body-parser');
var proxy = httpProxy.createProxyServer({secure:false});
var jsonParser = bodyParser.json();

proxy.on('proxyReq', function(proxyReq, req, res, options) {
    logger.debug("proxying for",req.url);
    //set headers
    logger.debug('proxy request forwarded succesfully');
});

proxy.on('error', function (err, req, res) {
  res.writeHead(500, {
    'Content-Type': 'text/plain'
  });
  res.end('Something went wrong. And we are reporting a custom error message.');
});

proxy.on('proxyRes', function (proxyRes, req, res) {
  console.log('RAW Response from the target', JSON.stringify(proxyRes.headers, true, 2));
});

module.exports = function(app){
  app.post('/recording',jsonParser,function(req,res){
    // update request body
    proxy.web(req, res, { target: <<host>>:<<port>>});
  });
}

app.js
---------

var express = require('express');
var app = express();
 require('./routes')(app);

app.listen(8080);
console.log("Demo server running");

我还使用bodyparser中间件,它有一个已知的问题,如Gitbug问题中所述所以我尝试将这一行添加为app.js的最后一行

app.use(require('connect-restreamer')());

但是POST请求仍然挂起并最终失败。我该如何解决 ?bodyparser是否有其他选择?

武士

尝试颠倒bodyParser和代理中间件的顺序:

module.exports = function(app){
  app.post('/recording', function(req,res){
    // update request body
    proxy.web(req, res, { target: <<host>>:<<port>>});
  }, jsonParser);
}

认为此问题类似于:nodejs的套接字挂起错误

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何为传出请求配置node-http-proxy?

来自分类Dev

如何为传出请求配置node-http-proxy?

来自分类Dev

将请求发布到Node-http-proxy Node.js时发生套接字挂断

来自分类Dev

防止有角度的 http post 请求超时

来自分类Dev

如何获得由node-http-proxy完成的每个代理请求的响应时间?

来自分类Dev

Ghost in a subdirectory and over node-http-proxy

来自分类Dev

node-http-proxy proxy.on('proxyReq'...)永远不会触发

来自分类Dev

angularjs:超时在$ http POST请求中不起作用

来自分类Dev

通过POST请求调用外部HTTP时,Cloud Functions超时

来自分类Dev

iOS:设置httpBody属性时,HTTP POST请求超时

来自分类Dev

子目录中的Ghost和node-http-proxy

来自分类Dev

node.js http-proxy自定义路由

来自分类Dev

node.js http-proxy自定义路由

来自分类Dev

Node.js:http请求在1分钟后超时

来自分类Dev

Node.js中的简单Http请求因以下错误代码而超时

来自分类Dev

链接多个Node http请求

来自分类Dev

/node_modules/http-proxy/lib/http-proxy/index.js:120; 错误:套接字挂断

来自分类Dev

Xamarin HTTP请求中的超时

来自分类Dev

Dart Http包请求超时

来自分类Dev

ionic http请求加载超时

来自分类Dev

通过PROXY,Ruby进行的HTTP2请求

来自分类Dev

如何在Ruby 2中为Net :: HTTP :: Post.new请求指定读取超时

来自分类Dev

Node JS上的HTTP请求回调

来自分类Dev

Node.js axios http请求循环

来自分类Dev

Node js http 请求:选项中的变量

来自分类Dev

从 AngularJS $http/AJAX 到基于 Node.js + Express.js 的 API 的 POST、PUT、DELETE 请求

来自分类Dev

如何在 node.js 中的 HTTP POST 请求之前做一些事情?

来自分类Dev

使用node-http-proxy从NodeJS到Apache的反向代理不起作用

来自分类Dev

如何在node-http-proxy中设置Access-Control-Allow-Headers标头

Related 相关文章

  1. 1

    如何为传出请求配置node-http-proxy?

  2. 2

    如何为传出请求配置node-http-proxy?

  3. 3

    将请求发布到Node-http-proxy Node.js时发生套接字挂断

  4. 4

    防止有角度的 http post 请求超时

  5. 5

    如何获得由node-http-proxy完成的每个代理请求的响应时间?

  6. 6

    Ghost in a subdirectory and over node-http-proxy

  7. 7

    node-http-proxy proxy.on('proxyReq'...)永远不会触发

  8. 8

    angularjs:超时在$ http POST请求中不起作用

  9. 9

    通过POST请求调用外部HTTP时,Cloud Functions超时

  10. 10

    iOS:设置httpBody属性时,HTTP POST请求超时

  11. 11

    子目录中的Ghost和node-http-proxy

  12. 12

    node.js http-proxy自定义路由

  13. 13

    node.js http-proxy自定义路由

  14. 14

    Node.js:http请求在1分钟后超时

  15. 15

    Node.js中的简单Http请求因以下错误代码而超时

  16. 16

    链接多个Node http请求

  17. 17

    /node_modules/http-proxy/lib/http-proxy/index.js:120; 错误:套接字挂断

  18. 18

    Xamarin HTTP请求中的超时

  19. 19

    Dart Http包请求超时

  20. 20

    ionic http请求加载超时

  21. 21

    通过PROXY,Ruby进行的HTTP2请求

  22. 22

    如何在Ruby 2中为Net :: HTTP :: Post.new请求指定读取超时

  23. 23

    Node JS上的HTTP请求回调

  24. 24

    Node.js axios http请求循环

  25. 25

    Node js http 请求:选项中的变量

  26. 26

    从 AngularJS $http/AJAX 到基于 Node.js + Express.js 的 API 的 POST、PUT、DELETE 请求

  27. 27

    如何在 node.js 中的 HTTP POST 请求之前做一些事情?

  28. 28

    使用node-http-proxy从NodeJS到Apache的反向代理不起作用

  29. 29

    如何在node-http-proxy中设置Access-Control-Allow-Headers标头

热门标签

归档