Welcome! Log In Create A New Profile

Advanced

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

August 08, 2016 05:50AM
Hello,

I have the following scenario:

- Client: AngularJS-based SPA running on www.example.com
- Backend: API running on api.example.com

Both live in one nginx instance in two separate "server" environments.

- Browsing to www.example.com/items/1 launches the Angular app
- App sends request to api.example.com/items/1
- If item 1 does not exist, API returns 404 status code
- Client app can now show soft 404 error page, all fine
- But for crawlers/search engines, I want to return a proper HTTP status code. Same goes for redirect to item’s canonical URL if that is necessary.

So my idea was to do sth like this:

- If request URL matches www.example.com/items/<id>, check existence of item by sending a HEAD request to api.example.com/items/<id>
- If request returns 404, return proper status code and error page
- If request returns 200, do nothing and just serve the Angular app

Is there any way to do this with (plain) nginx and if so–how could it be done specifically?

Thanks for any hints :)
Subject Author Posted

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

msonntag August 08, 2016 05:50AM

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

B.R. August 08, 2016 06:06AM

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

msonntag August 08, 2016 06:15AM

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

B.R. August 08, 2016 10:44AM

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

msonntag August 08, 2016 11:07AM

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

Edho Arief August 08, 2016 11:18AM

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

msonntag August 08, 2016 12:59PM

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

Edho Arief August 08, 2016 01:04PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 260
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready