Is it advisable for frontend apps to directly access backend API endpoints rather than employing proxy routing?

I’ve been developing a web app and I’m curious about the most effective way to manage API requests from the frontend to the backend.

In many guides and examples, the recommended practice is to use /api/* paths on the same domain, allowing nginx or a similar reverse proxy to handle the requests and direct them to the actual backend server. For instance, if my frontend is hosted at example.com, it sends requests to example.com/api/users, and the proxy then relays these calls to backend-server.com/api/users.

But what if I bypass the proxy altogether? This would mean my frontend directly interacts with the backend domain, such as backend-server.com/api/users.

Are there any significant technical issues that could arise from this direct method? Since I’m working on a small personal project, going direct appears more straightforward, as I wouldn’t need to set up proxy configurations or deal with routing complexities. Still, I aim to ensure that this choice won’t introduce security risks or other complications later on.

What potential downsides are there to directly calling the backend API from the frontend?

Direct API calls work fine for smaller projects, but you’ll hit limitations eventually. The biggest pain is deployment flexibility - when your frontend and backend are locked to specific domains, scaling becomes difficult. I learned this the hard way while switching hosting providers, which required updating API endpoints across my entire frontend. CORS issues can also arise since you’re dealing with actual cross-origin requests rather than same-origin proxy requests. Additionally, exposing your backend domain directly allows users to view your API structure. While this isn’t necessarily a security risk, it does compromise your ability to hide implementation details. For personal projects, direct calls are manageable, but if you anticipate growth or need multiple environments, it’s better to adopt the proxy approach.

Interesting dilemma! What authentication are you using? Direct calls might expose tokens differently than a proxy setup. Also, what about staging vs production environments? Proxy seems like it’d make that transition smoother, but what do you think?

dude, i totally get it! for small projects, direct calls can be chill, but yeah, don’t forget about CORS headaches. if you ever wanna scale, a proxy might save ya some hassle. but honestly, for personal stuff, go ahead with direct calls, you should be good!