|
|
""" |
|
|
RAG ๊ฒ์ ์ฑ๋ด ๋ฉ์ธ ์คํ ํ์ผ |
|
|
""" |
|
|
|
|
|
|
|
|
import os |
|
|
import logging |
|
|
|
|
|
|
|
|
logging.basicConfig( |
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', |
|
|
level=logging.INFO |
|
|
) |
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
try: |
|
|
|
|
|
from app.app import app |
|
|
|
|
|
|
|
|
try: |
|
|
from flask_cors import CORS |
|
|
from app.app_device_routes import register_device_routes |
|
|
|
|
|
|
|
|
CORS(app, supports_credentials=True) |
|
|
|
|
|
|
|
|
DEVICE_SERVER_URL = os.getenv('DEVICE_SERVER_URL', 'http://localhost:5050') |
|
|
logger.info(f"์ฅ์น ์๋ฒ URL: {DEVICE_SERVER_URL}") |
|
|
|
|
|
|
|
|
from app.app import login_required |
|
|
|
|
|
|
|
|
from functools import wraps |
|
|
from flask import request, session, redirect, url_for |
|
|
|
|
|
def device_login_required(f): |
|
|
@wraps(f) |
|
|
def decorated_function(*args, **kwargs): |
|
|
|
|
|
if request.path.startswith('/api/device/'): |
|
|
logger.info(f"์ฅ์น API ์์ฒญ: {request.path} - ์ธ์ฆ ์ ์ธ") |
|
|
return f(*args, **kwargs) |
|
|
|
|
|
|
|
|
return login_required(f)(*args, **kwargs) |
|
|
return decorated_function |
|
|
|
|
|
|
|
|
register_device_routes(app, device_login_required, DEVICE_SERVER_URL) |
|
|
logger.info("์ฅ์น ๋ผ์ฐํธ ์ง์ ๋ฑ๋ก ์ฑ๊ณต") |
|
|
|
|
|
|
|
|
@app.errorhandler(404) |
|
|
def not_found(e): |
|
|
|
|
|
from flask import request, jsonify |
|
|
if request.path.startswith('/api/'): |
|
|
return jsonify({"success": False, "error": "์์ฒญํ API ์๋ํฌ์ธํธ๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."}), 404 |
|
|
|
|
|
return "ํ์ด์ง๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.", 404 |
|
|
except Exception as e: |
|
|
logger.error(f"์ฅ์น ๋ผ์ฐํธ ๋ฑ๋ก ์คํจ: {e}", exc_info=True) |
|
|
|
|
|
except ImportError as e: |
|
|
logger.error(f"์ฑ ๋ชจ๋ ๊ฐ์ ธ์ค๊ธฐ ์คํจ: {e}") |
|
|
raise |
|
|
|
|
|
if __name__ == '__main__': |
|
|
port = int(os.environ.get("PORT", 7860)) |
|
|
logger.info(f"์๋ฒ๋ฅผ http://0.0.0.0:{port} ์์ ์์ํฉ๋๋ค.") |
|
|
app.run(debug=False, host='0.0.0.0', port=port) |