Skip to content

Conversation

@morgan-wowk
Copy link

Why is this change needed:

  1. It centralizes the CORS logic for Tangle so we are not maintaining duplicate solutions.
  2. It introduces the ability to configure CORS, increasing support for various environment configuration:
    • Local development (frontend on localhost:3000, backend on localhost:8000)
    • Production deployments where the frontend and backend are on different domains
    • Multi-tenant deployments with multiple frontend URLs

@maxy-shpfy maxy-shpfy requested a review from Ark-kun January 9, 2026 16:22
Copy link
Collaborator

@maxy-shpfy maxy-shpfy left a 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(",")
Copy link
Collaborator

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?

Copy link
Author

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:
Copy link
Collaborator

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.

Copy link
Author

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).

@morgan-wowk morgan-wowk force-pushed the 01-08-refactor_centralize_cors_business_logic_into_tangle_middleware branch from 3d90d50 to 9d18a3c Compare January 9, 2026 17:27
@morgan-wowk
Copy link
Author

LGTM, but havent had a chance to test

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants