corydolphin / flask-cors

Cross Origin Resource Sharing ( CORS ) support for Flask
https://flask-cors.readthedocs.io/en/latest/index.html
MIT License
884 stars 138 forks source link

Regex Subdmain Match #240

Open esfoobar opened 5 years ago

esfoobar commented 5 years ago

I have been trying for a long time to match a subdmain for CORS. I'm using Zeit Now's serverless service, which generates a random URL that always ends with wheatpaste.now.sh, but can also work with the static domain staging.admin.wheatpaste.app.

The static domain works perfectly, but the Now.sh doesn't.

Here's the list I've defined in a settings object: CORS_ORIGINS='["https:\/\/(.)*\.wheatpaste\.now\.sh", "staging.admin.wheatpaste.app",]'

I tested using the regex tester and the URL https://wp-frontend-app-git-wp-168-events-frontend-setup.wheatpaste.now.sh matches.

I've also tried 'now.sh', and 'wheatpaste.now.sh'.

Any ideas what I'm doing wrong?

Thanks in advance!

wangonya commented 1 year ago

Had this issue too. Chipping in for others who may find this later. I was able to figure it out using the example given in #208 . So the regex needed for the origin in OP's case would be: .*\.wheatpaste\.now\.sh.

>>> import re
>>> re.match(".*\.wheatpaste\.now\.sh","https://wp-frontend-app-git-wp-168-events-frontend-setup.wheatpaste.now.sh")
<re.Match object; span=(0, 74), match='https://wp-frontend-app-git-wp-168-events-fronten>
>>>