What I have usually done with single-page applications is to have a single monolithic application server that returns both HTML and responds to AJAX requests. I'd put all AJAX endpoints (typically returning JSON) under a single namespace, say /api
. All other requests go to a catch-all and return index.html
.
This seems convoluted, and I'm wondering if there's a standard way to "doing it right".
One method I'm exploring is to set up nginx to route all requests containing the header accept: text/html
to an application server that just returns the HTML. All requests containing the header accept: application/json
would be routed to the api server. That seems logical, but I just made that up and for all I know it could be suboptimal.
I'm curious to get feedback as to whether or not there is a standard way of doing this, along with any links that I may have missed during my research.