Return proper status codes (404, 302) from client-side Single Page Application

msonntag nginx-forum at forum.nginx.org
Mon Aug 8 15:07:30 UTC 2016


Hey B. R.,

Thanks for getting back to me. I am pretty sure that I was not able to make
my point very clear.

The main point is that a client accessing www.example.com/items/1 is simply
delivered a HTML file bootstrapping an AngularJS app. The JS client will
then make a separate request to api.example.com/items/1 to fetch the data.
At this point, if the API returns a 404, there is no way to send a 404 for
the initial request, as the response was already sent. So my idea was to
make a "precheck" request via nginx to check the item's existence prior to
delivering the HTML file containing the JS client. Another way would be to
have the server-side application deliver the client bootstrapping file, but
that's not the way the architecture is currently set up.

Don't know if that makes sense. Looking at the documentation links you
provided, I do not really know what you are suggesting as a solution.

Maybe these SO questions are able to explain it better?!

http://stackoverflow.com/questions/35989950/how-to-notify-googlebot-about-404-pages-in-angular-spa
http://stackoverflow.com/questions/37334220/how-do-i-return-a-http-404-status-code-from-a-spa
http://stackoverflow.com/questions/14779190/in-a-single-page-app-what-is-the-right-way-to-deal-with-wrong-urls-404-errors

Thanks again for your input.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,268827,268845#msg-268845



More information about the nginx mailing list