-
-
Notifications
You must be signed in to change notification settings - Fork 84
Manage CORS configuration via environment variables using django-cors-headers #1487
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -137,12 +137,14 @@ | |||||||||||||
| "django_extensions", | ||||||||||||||
| "bootstrap4", | ||||||||||||||
| "sri", | ||||||||||||||
| "corsheaders", | ||||||||||||||
| # To ensure that exceptions inside other apps' signal handlers do not affect the integrity of file deletions within transactions, `django_cleanup` should be placed last in `INSTALLED_APPS`. See https://github.com/un1t/django-cleanup#configuration | ||||||||||||||
| "django_cleanup.apps.CleanupConfig", | ||||||||||||||
| ] | ||||||||||||||
|
|
||||||||||||||
| MIDDLEWARE = [ | ||||||||||||||
| "debug_toolbar.middleware.DebugToolbarMiddleware", | ||||||||||||||
| "corsheaders.middleware.CorsMiddleware", | ||||||||||||||
| "django.middleware.security.SecurityMiddleware", | ||||||||||||||
| "django.contrib.sessions.middleware.SessionMiddleware", | ||||||||||||||
| "django.middleware.locale.LocaleMiddleware", | ||||||||||||||
|
|
@@ -586,6 +588,7 @@ def before_send(event, hint): | |||||||||||||
| }, | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| ########################### | ||||||||||||||
| # Django axes configuration | ||||||||||||||
| # https://django-axes.readthedocs.io/en/latest/4_configuration.html | ||||||||||||||
| ########################### | ||||||||||||||
|
|
@@ -970,3 +973,30 @@ def before_send(event, hint): | |||||||||||||
| # "logo_alt": "Your logo description", | ||||||||||||||
| # "favicon": "path/to/favicon.ico", | ||||||||||||||
| # } | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| ########################### | ||||||||||||||
| # CORS settings | ||||||||||||||
| # Managed via django-cors-headers. | ||||||||||||||
| # Origins and credentials are configured through environment variables, | ||||||||||||||
| # so no nginx changes are needed when adding new clients. | ||||||||||||||
| # https://github.com/adamchainz/django-cors-headers | ||||||||||||||
| ########################### | ||||||||||||||
|
|
||||||||||||||
| # Comma-separated list of origins that are allowed to make cross-origin | ||||||||||||||
| # requests. Do not include trailing slashes. | ||||||||||||||
| # Example: CORS_ALLOWED_ORIGINS=https://app.example.com,http://localhost:5173 | ||||||||||||||
| CORS_ALLOWED_ORIGINS = [ | ||||||||||||||
| origin.strip() | ||||||||||||||
| for origin in os.environ.get("CORS_ALLOWED_ORIGINS", "").split(",") | ||||||||||||||
| if origin.strip() | ||||||||||||||
| ] | ||||||||||||||
|
Comment on lines
+989
to
+993
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Can you add a new helper function |
||||||||||||||
|
|
||||||||||||||
| # Only allow CORS on API endpoints – static files and pages are unaffected. | ||||||||||||||
| CORS_URLS_REGEX = r"^/api/.*$" | ||||||||||||||
|
|
||||||||||||||
| # Whether to include credentials (cookies, authorization headers) in | ||||||||||||||
| # cross-origin requests. Required when clients send auth tokens. | ||||||||||||||
| CORS_ALLOW_CREDENTIALS = bool( | ||||||||||||||
| int(os.environ.get("CORS_ALLOW_CREDENTIALS", 0)) | ||||||||||||||
| ) | ||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file has way too many diff lines. Please minimize to the actual subset of changes that matters. Also it seems you ran the script with Python 3.11 somehow. Make sure you use the pip-compile that is part of the app container. |
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.
See the docs example here: https://github.com/csgis/QFieldCloud/blob/b1f73e9074a3dc55fc359d8e0fa8c8607d1cf256/.env.example#L6