Cloud load balancer to Cloud Run routing issue

I have a domain say "abc.com" which i have configured to the load balancer in gcp which has a backend of cloud run service wtih flutter app and I have another cloud run service which has a flutter app with some different endpoints like say "/login" which I have added to the host and paths in the load balancer configuration but Im facing issue when i hit "abc.com/login" as it doesnt really show the page that it is supposed to show. one more thing you should know is that I have added the abc.com's cloud run service as the default any unmathced hosts and /login in other paths. 

The main problem arises when we have the load balancer in front the services the main domain "abc.com" is set to the abc-website cloud run service on the load balancer with the default and all unmatched hosts. So when the request "https://abc.com/login" when arrived to the specific backend it actually goes to the abc-app but it doesnt actually render the login page and it ends up showing the default abc-website's 404 error page. The root cause actually is unclear over here because there's something that is causing the request that defaults to the unmatched hosts.

The 404 error page is the custom page that has been designed in flutter which is being rendered when the static routes are not found for the abc-app and the same logic is for the abc-website, so what problem I'm facing is that whenever the request comes in at abc.com it loads correctly but when I hit abc.com/login the request goes to the correct cloud run service of abc-app which has defined the /login route but it renders the 404 page of the abc-website's cloud run service which is set to deafult all unmatched hosts in the load balancer

1 REPLY 1

Hi @avdhoot31 ,

You haven't mentioned what type of load balancer was used on your setup. You might be using a TCP Load Balancer that does not support URL redirection. As a workaround you will need to configure either one of the following load balancers below which supports URL redirection:

1. Internal HTTP(s) Load Balancer.
2. Global External HTTP(s) Load Balancer.
3. Classic External HTTP(s) Load Balancer.
4. Regional HTTP(s) Load Balancer.

Also, make sure that you have configured a Host and Path rule that any unmatched URLs should be redirected to the backend. Hence, the url or path for abc-website should point to the backend for the cloud run service for abc-website, then create a separate backend for abc-app to prevent it from redirecting to 404 error page. 

Please be informed that in the Load Balancer configurations, you can redirect unmatched URLs to the https://abc.com/login by adding the URL redirect. This can be the easiest way to achieve your endgoal.

If this will not work, I would recommend you to create a support case on your cloud console. This way, support/techs will be able to inspect and check your project, the load balancer/s, and configured host-and-path rules. This way, they will be able to pin point what's causing the issue.