bobocup commited on
Commit
1920a28
·
verified ·
1 Parent(s): e3cd6c6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request
2
+ from fastapi.responses import Response
3
+ import requests
4
+
5
+ app = FastAPI()
6
+
7
+ @app.get("/{full_path:path}")
8
+ async def proxy(request: Request, full_path: str = ""):
9
+ try:
10
+ # 构建目标 URL
11
+ if full_path.startswith("api/"):
12
+ actual_path = full_path[4:]
13
+ target_url = f"http://beibeioo.top/{actual_path}"
14
+ else:
15
+ target_url = "http://beibeioo.top"
16
+
17
+ print(f"Forwarding to: {target_url}") # 调试日志
18
+
19
+ # 转发请求
20
+ response = requests.get(
21
+ target_url,
22
+ headers={
23
+ 'User-Agent': 'Mozilla/5.0',
24
+ 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
25
+ 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8'
26
+ }
27
+ )
28
+
29
+ return Response(
30
+ content=response.content,
31
+ status_code=response.status_code,
32
+ media_type=response.headers.get('content-type', 'text/html'),
33
+ headers={
34
+ 'Access-Control-Allow-Origin': '*',
35
+ 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
36
+ 'Access-Control-Allow-Headers': '*'
37
+ }
38
+ )
39
+ except Exception as e:
40
+ print(f"Error: {str(e)}") # 调试日志
41
+ return {"error": str(e)}
42
+
43
+ @app.get("/healthz")
44
+ async def health_check():
45
+ return {"status": "healthy"}