| from fastapi import FastAPI, Request |
| from fastapi.responses import Response, HTMLResponse |
| import requests |
|
|
| app = FastAPI() |
|
|
| @app.get("/", response_class=HTMLResponse) |
| @app.get("/{path:path}", response_class=HTMLResponse) |
| async def proxy(request: Request, path: str = ""): |
| try: |
| |
| if path.startswith("api/"): |
| actual_path = path[4:] |
| target_url = f"http://beibeioo.top/{actual_path}" |
| else: |
| target_url = "http://beibeioo.top" |
| |
| |
| response = requests.get( |
| target_url, |
| headers={ |
| 'User-Agent': 'Mozilla/5.0', |
| 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', |
| 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8', |
| } |
| ) |
| |
| |
| return Response( |
| content=response.content, |
| media_type=response.headers.get('content-type', 'text/html'), |
| headers={ |
| 'Access-Control-Allow-Origin': '*', |
| 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS', |
| 'Access-Control-Allow-Headers': '*' |
| } |
| ) |
| except Exception as e: |
| return HTMLResponse(content=f"Error: {str(e)}", status_code=500) |