Reasons to use the generic reverse proxy:
- You have a lot of different requests you need this for so it's simpler to have just one proxy that handles everything.
- Using nginx removes all work in processing the proxied requests to a separate process so it doesn't cause any load on your nodejs server.
- nginx "might" be more scalable than your own code in nodejs just because nginx is pretty highly optimized for these kinds of things. But, if this was a meaningful driver for your decision, you would have to measure to see if this was really the case or not (impossible to predict for sure without measuring).
Reasons to have your nodejs server do the work:
- You can do application-specific authentication before allowing a proxy request to be used.
- You can design application-specific requests that have your client specify only what you want to specify and your nodejs server can then translate that to the 3rd party website request, filling some parts with defaults, etc...
- You can trim the proxy response to just the data your client needs, speeding up client responses and trimming server bandwidth costs.
- You can combine multiple requests to the target into a single request/response between client and your nodejs server, allowing you to create more efficient requests, particularly on mobile or slow links.
Which is better depends entirely upon the specific requests and what exactly you're optimizing for. We can't name one as better than the other as they each have advantages and disadvantages so it ultimately comes down to which advantages and disadvantages matter more to you in your system.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…