Skip to content

Conversation

@chikamsoachumsft
Copy link
Owner

Refactor app initialization into a factory function and configure logging.

Refactor app initialization into a factory function and configure logging.
Copilot AI review requested due to automatic review settings October 29, 2025 21:39
Copy link

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 refactors the Flask application initialization to use the application factory pattern, improving testability and configuration management. It also adds comprehensive logging and better error handling.

  • Introduces a create_app() factory function that allows for dependency injection of configuration
  • Adds logging throughout the application lifecycle with proper error handling
  • Makes the application more configurable via environment variables (PORT, FLASK_ENV, FLASK_DEBUG)

base_dir: str = os.path.abspath(os.path.dirname(__file__))

app: Flask = Flask(__name__)
def create_app(config: dict = None) -> Flask:
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

El parámetro config debería usar dict[str, Any] o dict | None en lugar de dict para mayor precisión en el tipo. Además, considera usar Optional[dict[str, Any]] para mayor claridad sobre que puede ser None.

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

logger = logging.getLogger(__name__)

# Get the server directory path
base_dir: str = os.path.abspath(os.path.dirname(__file__))
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

La variable base_dir se define pero nunca se utiliza en el archivo. Considera eliminarla o úsala si tiene un propósito específico.

Suggested change
base_dir: str = os.path.abspath(os.path.dirname(__file__))

Copilot uses AI. Check for mistakes.
host='0.0.0.0' # Allow external connections
)
except ValueError:
logger.error("Invalid PORT environment variable")
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

El mensaje de error no incluye el valor inválido que causó el problema. Considera cambiar a logger.error(f"Invalid PORT environment variable: {os.getenv('PORT')}") para facilitar la depuración.

Suggested change
logger.error("Invalid PORT environment variable")
logger.error(f"Invalid PORT environment variable: {os.getenv('PORT')}")

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI commented Jan 22, 2026

@chikamsoachumsft I've opened a new pull request, #27, to work on those changes. Once the pull request is ready, I'll request review from you.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants