node.js/express 中的代理请求 [英] proxy request in node.js / express

查看:74
本文介绍了node.js/express 中的代理请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 nginx 服务器作为 node.js 应用程序的前端.
当请求到达应用程序时,我想稍微修改它(请求)并将其转发到另一个 node.js 应用程序.这样做的最佳方法是什么?

I have a nginx server as a front end to a node.js application.
When the request gets to the application, I'd like to slightly modify it (the request) and forward it to another node.js application. What would be the best way to do this ?

我正在考虑使用 node-proxy,但是当我在 node 应用程序中使用 expressjs 时,我不太确定如何同时使用 node-proxy 和 express.

I was thinking of node-proxy but as I use expressjs in the node apps, I'm not really sure how to use node-proxy and express at the same time.

有什么想法吗?

更新

我可以在 expressjs 路由中使用 res.redirect 转发到其他 node.js 应用程序吗?我刚刚试过这个,但它没有按预期工作.

Could I use res.redirect in my expressjs routes to forward to other node.js application ? I have just tried this but it does not work as expected.

推荐答案

res.redirect('http://otherapp.com') 应该可以工作,如果你让你的其他应用程序监听另一个端口或主机/域名,但是请求对象可能不会按照您的预期传递.你是如何修改它的?

res.redirect('http://otherapp.com') should work if you have your other app listening on another port or host/domain name, but the request object may not be passed on as you expect. How are you modifying it?

这篇关于node.js/express 中的代理请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆