你好我有这个问题我还没找到一个anwser。 我想创建像我附加的图像。
正常的工作流程应该是这样的:
- 客户端向服务器1发送请求;
- 服务器1收到请求;
- 服务器1向客户端发送302(重定向)响应;
- 然后客户端向服务器2发送新的http请求;
- 服务器2收到请求;
- 服务器2向客户端发送200(ok)响应;
醇>
而不是我想要实现的目标:
- 客户端向服务器1发送请求;
- 服务器1收到请求;
- 服务器1将请求转发给服务器2;
- 服务器2收到请求;
- 服务器2向客户端发送直接响应;
醇>
所以我不想从服务器1向客户端发送重定向响应,然后从客户端向服务器2发送新请求!
有可能用node.js或者至少用python实现类似的东西。我希望这种架构能够加速我的服务,因为服务器 - 服务器连接远比客户端 - 服务器连接快得多。
答案 0 :(得分:1)
If you need to do some logic before server1 perform the request to server2 (for example selecting the endpoint in server 2 based on some condition on request) then you can use request function from the Node.js standard library console.log($(event.currentTarget).closest('.content').find('.imgRef').val());
module (see docs at https://nodejs.org/dist/latest-v4.x/docs/api/http.html#http_http_request_options_callback). But if you don't need to perform any logic then is better to go with https://www.npmjs.com/package/http-proxy because you avoid a lot of boilerplate code.
答案 1 :(得分:0)
You need to use a proxy.
Something like https://www.npmjs.com/package/http-proxy
or you can use nginx or similar in front of a node.js server to be the proxy.
The only thing is the requests have to go back through the proxy, because thats how tcp connections work