ka1kuk commited on
Commit
b137e67
1 Parent(s): e1c331f

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +7 -3
main.py CHANGED
@@ -1,4 +1,4 @@
1
- from fastapi import FastAPI, HTTPException, Query
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 = 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)
 
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)