1
votes

I have an Express app used by several companies. Each company has its own subdomain to call the app api, such as company1.mydomain.com, company2.mydomain.com. In Express we read the value of the subdomain to determine the custom operation that we have to do for that company.

We are moving this app to GCP using Cloud Run with a GCP Load Balancer, setting all subdomains on the latter. We are now trying to read the subdomain but it contains the subdomain value of the Cloud Run URL (xxxxx.a.run.app). We are trying to figure out how to get the subdomain the user is requesting (the one configured in the Load Balancer) but that value doesn't seem to be forwarded to Cloud RUN.

Are there any settings that we are missing or something that help us to read the subdomain value from Cloud Run?

PD: We tried using Load Balancer's Custom Header but there is no option related to subdomain value

PD2: We also tried checking the other headers (including the X-Somethingxx GCP headers) and found nothing

1
Did you inspect the headers? Do you have the x-forwarded-host header value?guillaume blaquiere
@guillaumeblaquiere No, I don't have it. The x- Headers that I can see are: x-cloud-trace-context, x-forwarded-for, x-forwarded-proto and x-request-id. None of them contains the subdomainSebastian Sanchez
Do you use HTTPS protocol on your load balancer?guillaume blaquiere
@guillaumeblaquiere Yes. We have an HTTPS LB and HTTP LB redirecting to HTTPS.Sebastian Sanchez

1 Answers

1
votes

I found a solution. It's based on a recent article that I wrote.

The solution is:

  • Create a HTTPS load balancer
  • Define an internet NEG that call run.app
  • In the backend, use this NEG and add custom header host, with the value of the fully qualified URL of your Cloud Run service xxxxx.a.run.app (like described in my article)
  • Add another custom header (this one that you want, for example x-forwarded-host) with the value {tls_sni_hostname}