-
Notifications
You must be signed in to change notification settings - Fork 13
refactor: Centralize CORS business logic into Tangle middleware #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
maxy-shpfy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but havent had a chance to test
| # Parse the comma-separated list and strip whitespace from each origin | ||
| allowed_origins = [ | ||
| origin.strip() | ||
| for origin in cors_origins_str.split(",") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to add more sanity-checks (aka valid URLs) since it is a user-input?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea. I am sure this will help some people.
I have added some validation and useful messages when invalid formats are detected.
| ) | ||
|
|
||
|
|
||
| def setup_global_middleware(app: fastapi.FastAPI) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: No idea what naming conventions usually are, but since the usage is middleware.setup_global_middleware , maybe we simplify to middlware.setup? Not sure what not "global" middleware we may have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think setup is fine for now as well. Thank you!
Until we have a group of middleware to call, I am just calling setup_cors_middleware directly now (1 less function).
3d90d50 to
9d18a3c
Compare
Thanks for reviewing. I have added tests to the PR now as well to verify the middleware is meeting expectations, then will test again on staging with actual requests. |
Why is this change needed:
localhost:3000, backend onlocalhost:8000)