0

I have an Angular application deployed with an apache server on the same pod in the cluster. In my vhost file, I have a couple of directives, that I am using to proxy to my other backend applications in the cluster.

The issue that I am facing, is that I need to access one of my backend endpoints, through my frontend ui.

the host is: https://my-app my backend api is: api/backend/download

I need to use the following: https://my-app/api/backend/download. The issue is when I receive an error from my backend endpoint, it will display the json in the browser. I need to redirect to https://my-app/error-page.

What I tried up until now is using an ErrorDocument as follows:

<Location /api/backend/download> ...proxy setups ProxyOverride On ErrorDocuent 401 /error-page

But this keepts the url in the browser, which in turn will get picked up by angular wildcard, not the /error-page route I have defined.

I also tried RewriteRule as:

<Location /api/backend/download> ...proxy setups RewriteEngine On RewriteRule ^/download /error-page

But this as well doesn't seem to change the url in the broser. Does anyone have any ideea how can I redirect on 401 status code to my error-page route??

Thanks in advance

1 Answer 1

0

So I managed to do it like this:

<Location /api/backend/download> ...the proxy setup ErrorDocument 401 /to-error-401 </Location> <Location /to-error-401> RewriteEngine On RewriteRule (.*) /error-401 [L,R=301] </Location> <Location /error-401> FallbackResource /index.html </Location> 

So, the main issue was that the url in the browser would not be changed on ErrorDocument as ErrorDocument does the redirect internally. When the redirect occured, Angular picked up the route in the backend, in this case /api/backend/download, would not find any route similar as none was defined, and it will get picked by the wildcard route (which would route to a default route, if the url doesn't match the route specified). Why I didn't create 1 single Location, was because if I would do RewriteRule and make the url change, it will remain in an infinite loop, calling itself.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.