-
Notifications
You must be signed in to change notification settings - Fork 14
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
Implement Dynamic CORS Configuration (Fixes #2) #10
Implement Dynamic CORS Configuration (Fixes #2) #10
Conversation
- Added support for configuring allowed CORS origins dynamically from the .env file as a comma-separated list - Parsed and validated origins as `Uri`, converting them to `HeaderValue` for CORS configuration - Implemented error handling for invalid origins and failed conversions to `HeaderValue` - Enhanced CORS flexibility for multiple environments (development, staging, production) - Added logging for invalid or unparseable origins to assist in debugging
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.
@HarshitShukla-dev , load the environment variable in constants.rs
. and then use the constant in main.rs
.
- implemented the reading of cors origins from the .env file by loading the env file in constants.rs and then using the constants utility to read the value of ALLOWED_ORIGINS in main.rs
I’m sorry for the oversight. I've successfully loaded the environment variable in constants.rs and integrated the constant into main.rs. The ALLOWED_ORIGINS variable is now dynamically configured based on the values specified in the .env file. Additionally, I've added error handling to ensure that the application gracefully handles any issues related to the environment variable. If you have any further suggestions or need additional changes, please let me know! Thanks! |
If |
…RIGINS - Updated constants.rs to exit the program if the ALLOWED_ORIGINS environment variable is not set
@Sidharth-Singh10, Fixed the issues. |
@HarshitShukla-dev , thanks for the work!!! |
Hey @Sidharth-Singh10, it'll great if you assign the hacktoberfest and gssoc labels to both the pr and the issue. |
This pull request addresses issue #2 by introducing dynamic CORS configuration to the backend. The changes allow the application to read allowed origins from an environment variable defined in the
.env
file, enhancing flexibility for different deployment environments (development, staging, production).Key Changes:
.env
file as a comma-separated string.Uri
types, with any invalid URLs logged as warnings.Uri
toHeaderValue
for compatibility with theAllowOrigin::exact()
method in the CORS configuration.Reminder:
Please ensure to update the
.env
file with theALLOWED_ORIGINS
variable in the following format: