AIBOT111 commited on
Commit
ae8df65
·
verified ·
1 Parent(s): 53d8a87

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, Response
2
+ from flask_cors import CORS
3
+ import requests
4
+
5
+ app = Flask(__name__)
6
+ CORS(app) # Allow all origins (or customize if needed)
7
+
8
+ @app.route('/<path:url>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'])
9
+ def proxy(url):
10
+ # Convert path back into full URL
11
+ if not url.startswith("http"):
12
+ url = "https://" + url
13
+
14
+ try:
15
+ headers = {k: v for k, v in request.headers if k.lower() != 'host'}
16
+
17
+ response = requests.request(
18
+ method=request.method,
19
+ url=url,
20
+ headers=headers,
21
+ data=request.get_data(),
22
+ cookies=request.cookies,
23
+ allow_redirects=False,
24
+ )
25
+
26
+ excluded_headers = ['content-encoding', 'content-length', 'transfer-encoding', 'connection']
27
+ headers = [(k, v) for k, v in response.raw.headers.items() if k.lower() not in excluded_headers]
28
+
29
+ return Response(response.content, response.status_code, headers)
30
+ except Exception as e:
31
+ return {"error": str(e)}, 500
32
+
33
+ if __name__ == "__main__":
34
+ app.run(host="0.0.0.0", port=7860)