ChemApi / main.py
ka1kuk's picture
Update main.py
ac6ba74
raw
history blame
No virus
913 Bytes
from fastapi import FastAPI, HTTPException, Query
from fastapi.middleware.cors import CORSMiddleware
import httpx
app = FastAPI()
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
async def proxy(url: str = Query(..., description="URL to proxy")):
headers = {
'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'
}
async with httpx.AsyncClient() as client:
try:
response = await client.get(url, headers=headers)
return response.content
except httpx.RequestError as e:
raise HTTPException(status_code=500, detail="Unexpected error")
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)