Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

express - Forward requested subdomain/host from GCP Load Balancer to Cloud Run

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

question from:https://stackoverflow.com/questions/66066897/forward-requested-subdomain-host-from-gcp-load-balancer-to-cloud-run

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...