Spaces:
Paused
Paused
Upload 3 files
Browse filesFiles changed (3)
- DockerfileAdded+16
- app.pyAdded+27
- requirements.txtAdded+3
12345678910111213141516# Use the official Python image from the Docker Hub
FROM python:3.9
# Create a user and set the working directory
RUN useradd -m -u 1000 user
WORKDIR /app
# Copy the requirements file and install dependencies
COPY --chown=user ./requirements.txt requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements.txt
# Copy the application code
COPY --chown=user . /app
# Set the entry point to run the FastAPI server
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]123456789101112131415161718192021222324252627from fastapi import FastAPI, Request
from fastapi.responses import Response
import requests
app = FastAPI()
@app.get("/")
async function handleRequest(request: Request):
target_url = request.query_params.get('url')
if not target_url:
return Response(content="Missing 'url' query parameter", status_code=400)
try:
resp = requests.get(target_url, headers={'User-Agent': 'Mozilla/5.0'})
excluded_headers = ['content-encoding', 'content-length', 'transfer-encoding', 'connection']
headers = {k: v for k, v in resp.headers.items() if k.lower() not in excluded_headers}
content_type = resp.headers.get('content-type')
if content_type and 'text/html' in content_type:
text = resp.text
text = text.replace('href="/', f'href="?url={target_url}/')
text = text.replace('src="/', f'src="?url={target_url}/')
return Response(content=text, headers=headers, status_code=resp.status_code)
return Response(content=resp.content, headers=headers, status_code=resp.status_code)
except Exception as e:
return Response(content=f"Error fetching {target_url}: {str(e)}", status_code=500)123fastapi
uvicorn
requestsDockerfileAdded+16
app.pyAdded+27
requirements.txtAdded+3