diff --git a/main.py b/main.py index cd9f6bb..de4bca7 100644 --- a/main.py +++ b/main.py @@ -1,21 +1,23 @@ from runner.proxy import run_proxy -import subprocess import threading +import uvicorn +from runner.backend import app + +def run_fastapi_server(): + """FastAPI 서버를 실행하는 함수""" + uvicorn.run(app, host="localhost", port=11081, log_level="info") if __name__ == "__main__": - # Start web server in a separate thread - server_process = subprocess.Popen([ - "granian", - "--interface", "asgi", - "--host", "0.0.0.0", - "--port", "11081", - "--loop", "asyncio", - "--reload", - "runner.backend:app", - ]) - try: - # Run mitmdump proxy + # FastAPI 서버를 백그라운드 스레드에서 실행 + fastapi_thread = threading.Thread(target=run_fastapi_server, daemon=True) + fastapi_thread.start() + print("🚀 FastAPI server started on http://localhost:11081") + + # Run mitmdump proxy (메인 스레드에서 실행) + print("🛡️ Starting mitmdump proxy on port 11080...") run_proxy() + except KeyboardInterrupt: + print("🛑 Shutting down...") finally: - server_process.terminate() \ No newline at end of file + print("✅ Mitmdump proxy has been stopped.") \ No newline at end of file diff --git a/runner/backend/__init__.py b/runner/backend/__init__.py index 9af9555..4b60e63 100644 --- a/runner/backend/__init__.py +++ b/runner/backend/__init__.py @@ -20,4 +20,4 @@ async def not_found_handler(request, exc): @app.exception_handler(405) async def method_not_allowed_handler(request, exc): - return Response(status_code=405) \ No newline at end of file + return Response(status_code=405)