| | from flask import Flask, request, Response |
| | import requests |
| |
|
| | app = Flask(__name__) |
| |
|
| | PROXY_TARGET = "https://fastgpt.ltcld.cn/chat/share?shareId=a8s9p96b6c329asq8koajvdy" |
| |
|
| | @app.route('/') |
| | def home(): |
| | global PROXY_TARGET |
| | |
| | resp = requests.get(f"{PROXY_TARGET}{request.full_path}") |
| | |
| | excluded_headers = ['content-encoding', 'content-length', 'transfer-encoding', 'connection'] |
| | headers = [(name, value) for (name, value) in resp.raw.headers.items() |
| | if name.lower() not in excluded_headers] |
| | response = Response(resp.content, resp.status_code, headers) |
| | return response |
| |
|
| | @app.route('/<path:path>', methods=['GET', 'POST', 'PUT', 'DELETE']) |
| | def proxy(path): |
| | global PROXY_TARGET |
| | |
| | url = f"{PROXY_TARGET}/{path}" |
| | |
| | if request.method == 'GET': |
| | resp = requests.get(url, stream=True) |
| | elif request.method == 'POST': |
| | resp = requests.post(url, json=request.json, stream=True) |
| | elif request.method == 'PUT': |
| | resp = requests.put(url, json=request.json, stream=True) |
| | elif request.method == 'DELETE': |
| | resp = requests.delete(url, stream=True) |
| | |
| | |
| | excluded_headers = ['content-encoding', 'content-length', 'transfer-encoding', 'connection'] |
| | headers = [(name, value) for (name, value) in resp.raw.headers.items() |
| | if name.lower() not in excluded_headers] |
| | |
| | def generate(): |
| | for chunk in resp.iter_content(chunk_size=8192): |
| | yield chunk |
| | |
| | return Response(generate(), resp.status_code, headers) |
| |
|
| | if __name__ == '__main__': |
| | app.run(host='0.0.0.0', port=7860, debug=True) |
| |
|