Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/google-cloudrun-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
region: '${{ env.REGION }}'
image: 'gcr.io/${{ env.PROJECT_ID }}/${{ env.BACKEND_SERVICE }}:${{ github.sha }}'
env_vars: |
ENVIRONMENT=production
AZURE_TENANT_ID=${{ secrets.AZURE_TENANT_ID }}
AZURE_CLIENT_ID=${{ secrets.AZURE_CLIENT_ID }}
AZURE_CLIENT_SECRET=${{ secrets.AZURE_CLIENT_SECRET }}
Expand Down
41 changes: 39 additions & 2 deletions backend/main.py
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
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using print() statements for logging is not recommended in production applications. Replace with proper logging using Python's logging module (e.g., logging.info()) to enable proper log levels, formatting, and integration with cloud logging services.

Copilot uses AI. Check for mistakes.

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"])
Expand Down