From 4c895d6deb07443fd38fdf1cae8b974dcb73fdfa Mon Sep 17 00:00:00 2001 From: DarkSlein Date: Tue, 1 Jul 2025 13:49:32 +0300 Subject: [PATCH] Added hotfixes --- Dockerfile | 2 +- app.py | 39 ++------------------------------------- src/app.py | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 38 deletions(-) create mode 100644 src/app.py diff --git a/Dockerfile b/Dockerfile index daffbcf..b41cd22 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,4 +12,4 @@ COPY . . ENV PYTHONPATH="${PYTHONPATH}:/app" -CMD ["gunicorn", "-b", "0.0.0.0:5000", "-k", "geventwebsocket.gunicorn.workers.GeventWebSocketWorker", "--workers", "1", "app:create_app"] \ No newline at end of file +CMD ["gunicorn", "--worker-class", "geventwebsocket.gunicorn.workers.GeventWebSocketWorker", "-w", "1", "-b", "0.0.0.0:5000", "app:app"] \ No newline at end of file diff --git a/app.py b/app.py index fc0c9d4..624de80 100644 --- a/app.py +++ b/app.py @@ -1,38 +1,3 @@ -from gevent import monkey -monkey.patch_all() +from src.app import create_app -from werkzeug.serving import run_simple -from flask_cors import CORS -from pymongo import MongoClient - -from src.config import Config -from src.singletons.database_singleton import DatabaseSingleton - -from src.infra.server import app, socketio -from src.controllers.user_controller import user_blueprint -from src.controllers.reservation_controller import reservation_blueprint -from src.controllers.health_controller import health_blueprint -from src.controllers.room_controller import room_blueprint - -CORS(app) -app.config['JWT_SECRET_KEY'] = Config.JWT_SECRET_KEY - -app.register_blueprint(user_blueprint, url_prefix='/user') -app.register_blueprint(reservation_blueprint, url_prefix='/reservation') -app.register_blueprint(room_blueprint, url_prefix='/room') -app.register_blueprint(health_blueprint, url_prefix='/health') - -client = MongoClient(Config.MONGO_URI) -db = DatabaseSingleton.get_instance() - -if db is not None: - print('Connected to MongoDB') -else: - print('Failed to connect to MongoDB') - -def create_app(): - return app - -if __name__ == '__main__': - #app.run(debug=True) - socketio.run(app, host=Config.APP_HOST, debug=False) \ No newline at end of file +app = create_app() \ No newline at end of file diff --git a/src/app.py b/src/app.py new file mode 100644 index 0000000..e8586d8 --- /dev/null +++ b/src/app.py @@ -0,0 +1,41 @@ +from gevent import monkey +monkey.patch_all() + +from flask_cors import CORS +from pymongo import MongoClient + +import os +import sys + +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sys.path.insert(0, BASE_DIR) + +from config import Config +from singletons.database_singleton import DatabaseSingleton +from infra.server import app, socketio +from controllers.user_controller import user_blueprint +from controllers.reservation_controller import reservation_blueprint +from controllers.health_controller import health_blueprint +from controllers.room_controller import room_blueprint + +CORS(app) +app.config['JWT_SECRET_KEY'] = Config.JWT_SECRET_KEY + +app.register_blueprint(user_blueprint, url_prefix='/user') +app.register_blueprint(reservation_blueprint, url_prefix='/reservation') +app.register_blueprint(room_blueprint, url_prefix='/room') +app.register_blueprint(health_blueprint, url_prefix='/health') + +client = MongoClient(Config.MONGO_URI) +db = DatabaseSingleton.get_instance() + +if db is not None: + print('Connected to MongoDB') +else: + print('Failed to connect to MongoDB') + +def create_app(): + return app + +if __name__ == '__main__': + socketio.run(app, host=Config.APP_HOST, debug=False) \ No newline at end of file