Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -77,12 +77,12 @@ async def proxy_openapi(request: Request):
|
|
| 77 |
return {"error": "Userbot API is booting up..."}
|
| 78 |
|
| 79 |
# Forward all /api/ traffic dynamically
|
| 80 |
-
@app.
|
| 81 |
async def proxy_to_userbot(request: Request, path: str):
|
| 82 |
url = f"http://127.0.0.1:{USERBOT_API_PORT}/api/{path}"
|
| 83 |
headers = dict(request.headers)
|
| 84 |
-
headers.pop("host", None)
|
| 85 |
-
|
| 86 |
try:
|
| 87 |
async with httpx.AsyncClient() as client:
|
| 88 |
route_method = getattr(client, request.method.lower())
|
|
@@ -92,4 +92,7 @@ async def proxy_to_userbot(request: Request, path: str):
|
|
| 92 |
)
|
| 93 |
return JSONResponse(status_code=response.status_code, content=response.json())
|
| 94 |
except Exception as e:
|
| 95 |
-
return JSONResponse(
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
return {"error": "Userbot API is booting up..."}
|
| 78 |
|
| 79 |
# Forward all /api/ traffic dynamically
|
| 80 |
+
@app.api_route("/api/{path:path}", methods=["GET", "POST", "PUT", "DELETE"])
|
| 81 |
async def proxy_to_userbot(request: Request, path: str):
|
| 82 |
url = f"http://127.0.0.1:{USERBOT_API_PORT}/api/{path}"
|
| 83 |
headers = dict(request.headers)
|
| 84 |
+
headers.pop("host", None)
|
| 85 |
+
|
| 86 |
try:
|
| 87 |
async with httpx.AsyncClient() as client:
|
| 88 |
route_method = getattr(client, request.method.lower())
|
|
|
|
| 92 |
)
|
| 93 |
return JSONResponse(status_code=response.status_code, content=response.json())
|
| 94 |
except Exception as e:
|
| 95 |
+
return JSONResponse(
|
| 96 |
+
status_code=502,
|
| 97 |
+
content={"error": f"Userbot API is offline or booting up. Exception: {str(e)}"},
|
| 98 |
+
)
|