Python allow-origin with multiple subdomains

Viewed 117

I deploy my web app with Netifly.

It has preview environment that looks this way:

"randomonstring33712638126--domaincom.netlify.app"

And I have a python function at Google Cloud, that I want to secure with allow-origin. How can I allow origin for all domains that ends with --domaincom.netlify.app?

I tried this, but seems like it's not working:

ALLOW_ORIGIN = 'https://domain[dot]com/, https://*--domaincom.netlify.app/'

Thank you for any help.

1 Answers

I'm afraid allowing subdomains isn't something you can do with Access-Control-Allow-Origin.

Have a look at the docs: the Allow-Origin can accept

  • the wildcard, * (any origin)
  • a specified origin, e.g. https://example.app
  • or null

For limiting multiple domains it says

Limiting the possible Access-Control-Allow-Origin values to a set of allowed origins requires code on the server side to check the value of the Origin request header, compare that to a list of allowed origins, and then if the Origin value is in the list, set the Access-Control-Allow-Origin value to the same value as the Origin value.

Related