bcci commited on
Commit
453e604
·
verified ·
1 Parent(s): c445787

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess
2
+ import sys
3
+
4
+ # Step 1: Ensure fastapi and uvicorn are installed
5
+ def install_dependencies():
6
+ subprocess.run([sys.executable, "-m", "pip", "install", "--upgrade", "fastapi", "uvicorn", "httpx"], check=True)
7
+
8
+ try:
9
+ import fastapi
10
+ import uvicorn
11
+ import httpx
12
+ except ImportError:
13
+ install_dependencies()
14
+ import fastapi
15
+ import uvicorn
16
+ import httpx
17
+
18
+ from fastapi import FastAPI, Response
19
+ from fastapi.responses import PlainTextResponse
20
+
21
+ app = FastAPI()
22
+
23
+ # Step 2: Define endpoint to proxy ips.txt from port 5000
24
+ @app.get("/ips.txt", response_class=PlainTextResponse)
25
+ async def get_ips():
26
+ url = "http://207.180.209.185:5000/ips.txt"
27
+ try:
28
+ async with httpx.AsyncClient(timeout=5.0) as client:
29
+ response = await client.get(url)
30
+ response.raise_for_status()
31
+ return Response(content=response.text, media_type="text/plain")
32
+ except httpx.RequestError as e:
33
+ return Response(content=f"Error fetching data: {str(e)}", media_type="text/plain", status_code=500)