Update main.py
Browse files
main.py
CHANGED
@@ -1,11 +1,10 @@
|
|
1 |
-
from fastapi import FastAPI, HTTPException,
|
2 |
from fastapi.middleware.cors import CORSMiddleware
|
3 |
-
|
4 |
-
import requests
|
5 |
|
6 |
app = FastAPI()
|
7 |
|
8 |
-
# Add CORS middleware
|
9 |
app.add_middleware(
|
10 |
CORSMiddleware,
|
11 |
allow_origins=["*"],
|
@@ -15,17 +14,17 @@ app.add_middleware(
|
|
15 |
)
|
16 |
|
17 |
@app.get("/")
|
18 |
-
|
19 |
-
async def proxy(request: Request, url: str):
|
20 |
headers = {
|
21 |
-
|
22 |
}
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
29 |
|
30 |
if __name__ == "__main__":
|
31 |
import uvicorn
|
|
|
1 |
+
from fastapi import FastAPI, HTTPException, Query
|
2 |
from fastapi.middleware.cors import CORSMiddleware
|
3 |
+
import httpx
|
|
|
4 |
|
5 |
app = FastAPI()
|
6 |
|
7 |
+
# Add CORS middleware
|
8 |
app.add_middleware(
|
9 |
CORSMiddleware,
|
10 |
allow_origins=["*"],
|
|
|
14 |
)
|
15 |
|
16 |
@app.get("/")
|
17 |
+
async def proxy(url: str = Query(..., description="URL to proxy")):
|
|
|
18 |
headers = {
|
19 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
20 |
}
|
21 |
+
|
22 |
+
async with httpx.AsyncClient() as client:
|
23 |
+
try:
|
24 |
+
response = await client.get(url, headers=headers)
|
25 |
+
return response.content
|
26 |
+
except httpx.RequestError as e:
|
27 |
+
raise HTTPException(status_code=500, detail="Unexpected error")
|
28 |
|
29 |
if __name__ == "__main__":
|
30 |
import uvicorn
|