Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,15 +5,15 @@ import os
|
|
| 5 |
app = Flask(__name__)
|
| 6 |
|
| 7 |
|
| 8 |
-
TARGET_DOMAIN = os.getenv(TARGET_API)
|
| 9 |
-
|
| 10 |
-
@app.route('', defaults={'path' ''})
|
| 11 |
-
@app.route('
|
| 12 |
-
def proxy(path)
|
| 13 |
-
try
|
| 14 |
-
target_url = f{TARGET_DOMAIN}{path}
|
| 15 |
-
#print(
|
| 16 |
-
headers = {key value for (key, value) in request.headers if key.lower() not in ('host', 'content-length')}
|
| 17 |
headers['Accept-Encoding'] = 'identity' # 禁止压缩
|
| 18 |
|
| 19 |
resp = requests.request(
|
|
@@ -28,17 +28,18 @@ def proxy(path)
|
|
| 28 |
|
| 29 |
excluded_headers = ['content-encoding', 'content-length', 'transfer-encoding', 'connection']
|
| 30 |
headers = [(name, value) for (name, value) in resp.raw.headers.items() if name.lower() not in excluded_headers]
|
|
|
|
| 31 |
|
| 32 |
-
#headers.append(('Content-Type', '
|
| 33 |
|
| 34 |
return Response(resp.iter_content(chunk_size=1024), headers=headers, status=resp.status_code)
|
| 35 |
|
| 36 |
-
except Exception as e
|
| 37 |
return str(e), 500
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
-
if __name__ == '__main__'
|
| 43 |
# 必须指定host和port
|
| 44 |
app.run(host='0.0.0.0', port=7860, debug=False)
|
|
|
|
| 5 |
app = Flask(__name__)
|
| 6 |
|
| 7 |
|
| 8 |
+
TARGET_DOMAIN = os.getenv("TARGET_API")
|
| 9 |
+
|
| 10 |
+
@app.route('/', defaults={'path': ''})
|
| 11 |
+
@app.route('/<path:path>', methods=['GET', 'POST', 'PUT', 'DELETE'])
|
| 12 |
+
def proxy(path):
|
| 13 |
+
try:
|
| 14 |
+
target_url = f"{TARGET_DOMAIN}/{path}"
|
| 15 |
+
#print(f"Proxying to: {target_url}")
|
| 16 |
+
headers = {key: value for (key, value) in request.headers if key.lower() not in ('host', 'content-length')}
|
| 17 |
headers['Accept-Encoding'] = 'identity' # 禁止压缩
|
| 18 |
|
| 19 |
resp = requests.request(
|
|
|
|
| 28 |
|
| 29 |
excluded_headers = ['content-encoding', 'content-length', 'transfer-encoding', 'connection']
|
| 30 |
headers = [(name, value) for (name, value) in resp.raw.headers.items() if name.lower() not in excluded_headers]
|
| 31 |
+
|
| 32 |
|
| 33 |
+
#headers.append(('Content-Type', 'application/json; charset=utf-8'))
|
| 34 |
|
| 35 |
return Response(resp.iter_content(chunk_size=1024), headers=headers, status=resp.status_code)
|
| 36 |
|
| 37 |
+
except Exception as e:
|
| 38 |
return str(e), 500
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
+
if __name__ == '__main__':
|
| 44 |
# 必须指定host和port
|
| 45 |
app.run(host='0.0.0.0', port=7860, debug=False)
|