1616
1717from logger import setup_logger
1818from config import _SUPPORTED_BOOK_LANGUAGE , BOOK_LANGUAGE , SUPPORTED_FORMATS
19- from env import FLASK_HOST , FLASK_PORT , APP_ENV , CWA_DB_PATH , DEBUG , USING_EXTERNAL_BYPASSER , BUILD_VERSION , RELEASE_VERSION , CALIBRE_WEB_URL
19+ from env import FLASK_HOST , FLASK_PORT , CWA_DB_PATH , DEBUG , USING_EXTERNAL_BYPASSER , BUILD_VERSION , RELEASE_VERSION , CALIBRE_WEB_URL
2020import backend
2121
2222from models import SearchFilters
2828app .config ['SEND_FILE_MAX_AGE_DEFAULT' ] = 0 # Disable caching
2929app .config ['APPLICATION_ROOT' ] = '/'
3030
31- # Determine async mode based on environment
32- # In production with Gunicorn + gevent worker, use 'gevent'
33- # In development with Flask dev server, use 'threading'
34- if APP_ENV == 'prod' :
35- async_mode = 'gevent'
36- else :
31+ # Determine async mode based on DEBUG setting
32+ # In production (DEBUG=False) with Gunicorn + gevent worker, use 'gevent'
33+ # In development (DEBUG=True) with Flask dev server, use 'threading'
34+ if DEBUG :
3735 async_mode = 'threading'
36+ else :
37+ async_mode = 'gevent'
3838
3939# Initialize Flask-SocketIO with reverse proxy support
4040socketio = SocketIO (
@@ -152,16 +152,9 @@ def filter(self, record):
152152# The secret key will reset every time we restart, which will
153153# require users to authenticate again
154154
155- # Secure cookie handling (HTTP vs HTTPS)
156- # Can be overridden with SESSION_COOKIE_SECURE environment variable
157- session_cookie_secure_env = os .getenv ('SESSION_COOKIE_SECURE' , 'auto' ).lower ()
158- if session_cookie_secure_env in ['true' , 'yes' , '1' ]:
159- SESSION_COOKIE_SECURE = True
160- elif session_cookie_secure_env in ['false' , 'no' , '0' ]:
161- SESSION_COOKIE_SECURE = False
162- else :
163- # Auto mode: align with deployment environment
164- SESSION_COOKIE_SECURE = APP_ENV == 'prod'
155+ # Session cookie security - set to 'true' if exclusively using HTTPS
156+ session_cookie_secure_env = os .getenv ('SESSION_COOKIE_SECURE' , 'false' ).lower ()
157+ SESSION_COOKIE_SECURE = session_cookie_secure_env in ['true' , 'yes' , '1' ]
165158
166159app .config .update (
167160 SECRET_KEY = os .urandom (64 ),
@@ -382,7 +375,6 @@ def api_config() -> Union[Response, Tuple[Response, int]]:
382375 config = {
383376 "calibre_web_url" : CALIBRE_WEB_URL ,
384377 "debug" : DEBUG ,
385- "app_env" : APP_ENV ,
386378 "build_version" : BUILD_VERSION ,
387379 "release_version" : RELEASE_VERSION ,
388380 "book_languages" : _SUPPORTED_BOOK_LANGUAGE ,
@@ -394,6 +386,17 @@ def api_config() -> Union[Response, Tuple[Response, int]]:
394386 logger .error_trace (f"Config error: { e } " )
395387 return jsonify ({"error" : str (e )}), 500
396388
389+ @app .route ('/api/health' , methods = ['GET' ])
390+ def api_health () -> Union [Response , Tuple [Response , int ]]:
391+ """
392+ Health check endpoint for container orchestration.
393+ No authentication required.
394+
395+ Returns:
396+ flask.Response: JSON with status "ok".
397+ """
398+ return jsonify ({"status" : "ok" })
399+
397400@app .route ('/api/status' , methods = ['GET' ])
398401@login_required
399402def api_status () -> Union [Response , Tuple [Response , int ]]:
@@ -812,7 +815,7 @@ def handle_status_request():
812815logger .log_resource_usage ()
813816
814817if __name__ == '__main__' :
815- logger .info (f"Starting Flask application with WebSocket support on { FLASK_HOST } :{ FLASK_PORT } IN { APP_ENV } mode " )
818+ logger .info (f"Starting Flask application with WebSocket support on { FLASK_HOST } :{ FLASK_PORT } (debug= { DEBUG } ) " )
816819 socketio .run (
817820 app ,
818821 host = FLASK_HOST ,
0 commit comments