0

I separated my frontend from my backend and I am configuring my frontend part. I am doing API requests to the backend with a proxy middleware in production now and my question is, can it harm my frontend app in anyway? is there anything why I shouldn't use a middleware proxy for this?

for me, a middleware proxy is a smooth solution to communicate with the backend and everything works out of the box.

the other option would be to setup a bunch of CORS exceptions but I am not happy with that.

Noban Hasan
  • 593
  • 1
  • 7
  • 21
Deniz
  • 1,435
  • 14
  • 29
  • You limit yourself to using Node server to serve Vue while it could be served as static files, e.g directly by Nginx. – Estus Flask Oct 21 '20 at 22:47
  • @EstusFlask as far as i know express.js i not doing different then nginx or apache. it serves my static dist folder in a node.js driven http server. all i do is proxy my api requests to a backend. – Deniz Oct 22 '20 at 06:13
  • Nginx serves static files much more efficiently, that's its distinctive feature. It's unnecessarily that using app server to serve statics will be a bottleneck, but if you wanted to know how it can harm, that's how. That's an overhead that could be avoided. Any way, even with app server you can cache with Nginx to reduce it. It may be possible to rewrite CORS headers with Nginx alone but I can't comment on that. – Estus Flask Oct 22 '20 at 11:58

1 Answers1

0

Yes, but only if you're handling the scaling case.

Keep in mind that JavaScript is single-threaded. While NodeJS is quite efficient, at some point it is likely that user's requests will begin to timeout since the single thread isn't able to service all the requests. When that happens, you may end up needing to re-design your application.

Take a look at pm2 as well as cluster mode if you haven't already. As long as your proxy middleware is configured to work in tandem with this, you should be fine.

Guru Prasad
  • 4,053
  • 2
  • 25
  • 43
  • do you know any ways to test a scenario like this? then i would like to force this situation and check whats happening with my app when i get a requests queue. – Deniz Oct 22 '20 at 06:15
  • 1
    @Deniz Try load testing tool like Artillery or Apache AB. Also applies to a scenario with Nginx and without it. – Estus Flask Oct 22 '20 at 12:00