slimshadow commited on
Commit
15c9046
·
verified ·
1 Parent(s): 0130a88

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +16 -0
  2. app.py +27 -0
  3. requirements.txt +3 -0
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use the official Python image from the Docker Hub
2
+ FROM python:3.9
3
+
4
+ # Create a user and set the working directory
5
+ RUN useradd -m -u 1000 user
6
+ WORKDIR /app
7
+
8
+ # Copy the requirements file and install dependencies
9
+ COPY --chown=user ./requirements.txt requirements.txt
10
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
+
12
+ # Copy the application code
13
+ COPY --chown=user . /app
14
+
15
+ # Set the entry point to run the FastAPI server
16
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request
2
+ from fastapi.responses import Response
3
+ import requests
4
+
5
+ app = FastAPI()
6
+
7
+ @app.get("/")
8
+ async function handleRequest(request: Request):
9
+ target_url = request.query_params.get('url')
10
+ if not target_url:
11
+ return Response(content="Missing 'url' query parameter", status_code=400)
12
+
13
+ try:
14
+ resp = requests.get(target_url, headers={'User-Agent': 'Mozilla/5.0'})
15
+ excluded_headers = ['content-encoding', 'content-length', 'transfer-encoding', 'connection']
16
+ headers = {k: v for k, v in resp.headers.items() if k.lower() not in excluded_headers}
17
+
18
+ content_type = resp.headers.get('content-type')
19
+ if content_type and 'text/html' in content_type:
20
+ text = resp.text
21
+ text = text.replace('href="/', f'href="?url={target_url}/')
22
+ text = text.replace('src="/', f'src="?url={target_url}/')
23
+ return Response(content=text, headers=headers, status_code=resp.status_code)
24
+
25
+ return Response(content=resp.content, headers=headers, status_code=resp.status_code)
26
+ except Exception as e:
27
+ return Response(content=f"Error fetching {target_url}: {str(e)}", status_code=500)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ requests