Update main.py
Browse files
main.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from fastapi import FastAPI, HTTPException,
|
2 |
from fastapi.middleware.cors import CORSMiddleware
|
3 |
import httpx
|
4 |
|
@@ -13,12 +13,16 @@ app.add_middleware(
|
|
13 |
allow_headers=["*"],
|
14 |
)
|
15 |
|
16 |
-
@app.get("/")
|
17 |
-
async def proxy(url: str =
|
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)
|
|
|
1 |
+
from fastapi import FastAPI, HTTPException, Path
|
2 |
from fastapi.middleware.cors import CORSMiddleware
|
3 |
import httpx
|
4 |
|
|
|
13 |
allow_headers=["*"],
|
14 |
)
|
15 |
|
16 |
+
@app.get("/{url:path}")
|
17 |
+
async def proxy(url: str = Path(..., title="The URL to be proxied", description="The entire URL to be proxied")):
|
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 |
+
# Ensure the URL has a valid format
|
23 |
+
if not url.startswith(('http://', 'https://')):
|
24 |
+
raise HTTPException(status_code=400, detail="Invalid URL format")
|
25 |
+
|
26 |
async with httpx.AsyncClient() as client:
|
27 |
try:
|
28 |
response = await client.get(url, headers=headers)
|