app.py
1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
Flask main application entrypoint for the BettaFish web API.
"""
import sys
try:
from .bootstrap.import_path import ensure_project_root_on_sys_path
except ImportError: # pragma: no cover
from bootstrap.import_path import ensure_project_root_on_sys_path
PROJECT_ROOT = ensure_project_root_on_sys_path(__file__, sys.path)
from apps.web_api.bootstrap.app_module import bootstrap_app_module
from services.shared.config import get_settings
from services.shared.logging import bind_logger
_PREVIOUS_APP_MODULE = globals().get("_APP_MODULE")
_APP_MODULE = bootstrap_app_module(
previous_cleanup_handler=getattr(_PREVIOUS_APP_MODULE, "cleanup_handler", None),
)
app = _APP_MODULE.app
socketio = _APP_MODULE.socketio
def main() -> int:
"""Start the Flask + Socket.IO server using configured host and port."""
configured_settings = get_settings()
host = configured_settings.HOST
port = configured_settings.PORT
startup_logger = bind_logger(source="web_api.app", host=host, port=port)
startup_logger.info("Starting BettaFish web API server...")
startup_logger.info(f"Flask service listening at: http://{host}:{port}")
try:
socketio.run(app, host=host, port=port, debug=False)
except KeyboardInterrupt:
startup_logger.info("\nShutdown requested via keyboard interrupt...")
_APP_MODULE.cleanup_handler()
return 0
__all__ = ["app", "socketio", "main"]
if __name__ == "__main__":
raise SystemExit(main())