Hello I have this question I have not found an anwser yet.
I would like to create something like the image I attach.
The normal workflow should be something like this:
- Client sends a request to server 1;
- Server 1 receives the request;
- Server 1 sends a 302 (redirect) response to the client;
- Then client sends a new http request to server 2;
- Server 2 receives the request;
- Server 2 sends a 200 (ok) response to the client;
Instead of this I would like to realize something like:
- Client sends a request to server 1;
- Server 1 receives the request;
- Server 1 forward the request to server 2;
- Server 2 receives the request;
- Server 2 sends a direct response to the client;
So I do not want to send a redirect response from server 1 to client and then a new request from client to server 2!
It could be possible to realize something like this with node.js or, at least, with python?. I want this kind of architecture to speed up my service because server-server connection is far much faster then client-server connection.
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
http
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.