-
Notifications
You must be signed in to change notification settings - Fork 0
Release #17
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
Merged
Merged
Release #17
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
08afe20
feat: Enhance CORS configuration for production and development envir…
ChingEnLin 0ba7b95
fix: Update allowed origins for development environment in CORS confi…
ChingEnLin a5a335f
style: Refactor CORS configuration logic and improve formatting in ma…
ChingEnLin 1de345f
remove cors_allowed_origins from response
ChingEnLin 7a66b93
Update backend/main.py
ChingEnLin d607fc9
Merge pull request #16 from ChingEnLin/fix/cors
ChingEnLin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,55 @@ | ||
| import os | ||
| import uvicorn | ||
| from fastapi import FastAPI | ||
| from fastapi.middleware.cors import CORSMiddleware | ||
| from routes import query, azure, system, user_queries, data_documents | ||
|
|
||
| app = FastAPI() | ||
|
|
||
| # Configure CORS origins based on environment | ||
| # Check for production indicators | ||
| is_production = ( | ||
| os.getenv("ENVIRONMENT") == "production" | ||
| or os.getenv("K_SERVICE") is not None # Google Cloud Run | ||
| ) | ||
|
|
||
| if is_production: | ||
| # Production: Only allow specific origins | ||
| allowed_origins = [ | ||
| "https://querypal.virtonomy.io", # Production frontend | ||
| "https://querypal-frontend-zynyyoxona-ew.a.run.app", # Cloud Run frontend URL (pattern) | ||
| # Add your actual Cloud Run frontend URL when you know it | ||
| ] | ||
| else: | ||
| # Development: Allow localhost origins | ||
| allowed_origins = [ | ||
| "http://localhost:8000", | ||
| "http://localhost:5173", | ||
| "http://127.0.0.1:8000", | ||
| "http://127.0.0.1:5173", | ||
| ] | ||
|
|
||
| print(f"🔧 CORS Configuration - Production mode: {is_production}") | ||
| print(f"🌐 Allowed origins: {allowed_origins}") | ||
|
Comment on lines
+32
to
+33
|
||
|
|
||
| app.add_middleware( | ||
| CORSMiddleware, | ||
| allow_origins=["*"], | ||
| allow_origins=allowed_origins, | ||
| allow_credentials=True, | ||
| allow_methods=["*"], | ||
| allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"], | ||
| allow_headers=["*"], | ||
| ) | ||
|
|
||
|
|
||
| @app.get("/health") | ||
| async def health_check(): | ||
| """Health check endpoint.""" | ||
| return { | ||
| "status": "healthy", | ||
| "cors_production_mode": is_production, | ||
| } | ||
|
|
||
|
|
||
| app.include_router(query.router, prefix="/query", tags=["Query"]) | ||
| app.include_router(azure.router, prefix="/azure", tags=["Azure"]) | ||
| app.include_router(system.router, prefix="/system", tags=["System"]) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The Cloud Run URL appears to be a placeholder pattern rather than an actual frontend URL. Consider using an environment variable for the frontend URL instead of hardcoding it, or remove this entry if it's not yet deployed.