Skip to content

Conversation

@ChingEnLin
Copy link
Owner

This pull request improves the backend's security and configurability by introducing environment-aware CORS configuration and a new health check endpoint. It also updates the deployment workflow to set the production environment variable.

Backend CORS configuration and health check:

  • The backend (backend/main.py) now sets allowed CORS origins based on environment variables: in production, only specific frontend URLs are allowed; in development, localhost origins are permitted. This prevents unauthorized cross-origin requests in production.
  • The CORS middleware is now restricted to specific HTTP methods instead of allowing all methods.
  • Added a /health endpoint that returns the application's health status and current CORS configuration, making it easier to verify deployment and debug CORS issues.

Deployment workflow update:

  • The Cloud Run deployment workflow (.github/workflows/google-cloudrun-docker.yml) now sets the ENVIRONMENT=production environment variable, ensuring the backend runs in production mode when deployed.

Copilot AI review requested due to automatic review settings October 28, 2025 10:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances security by implementing environment-aware CORS configuration and adds operational monitoring capabilities. The backend now restricts cross-origin requests based on deployment environment, and the deployment workflow ensures the application runs in production mode.

Key Changes:

  • Environment-based CORS origin allowlist (production vs. development)
  • Restricted HTTP methods in CORS middleware from wildcard to specific methods
  • New /health endpoint exposing CORS configuration for debugging

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
backend/main.py Implements environment detection, conditional CORS origins, restricted HTTP methods, and health check endpoint
.github/workflows/google-cloudrun-docker.yml Sets ENVIRONMENT=production variable for Cloud Run deployments

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +34 to +35
print(f"🔧 CORS Configuration - Production mode: {is_production}")
print(f"🌐 Allowed origins: {allowed_origins}")
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.
ChingEnLin and others added 2 commits October 28, 2025 11:15
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@ChingEnLin ChingEnLin merged commit d607fc9 into dev Oct 28, 2025
3 checks passed
@ChingEnLin ChingEnLin deleted the fix/cors branch October 28, 2025 10:17
@github-actions
Copy link

🎉 This PR is included in version 2.4.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants