Spaces:
Running
Running
File size: 1,213 Bytes
3c2a81d 20f4cd1 3c2a81d 20f4cd1 3c2a81d 20f4cd1 3c2a81d cfea4a6 3c2a81d fac94c9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
from flask import Flask, request, Response
import requests
app = Flask("DiscordRocks Instant Chat Proxy")
DISCORD_ROCKS_HOST = 'chat.discord.rocks'
CHAT_UI_HOST = 'cutycat2000x-instantchat.static.hf.space'
@app.route('/',methods=['GET', 'POST'])
@app.route("/<path:path>", methods=['GET', 'POST'])
def handle_request(path=""):
chat_ui_url = f'https://{DISCORD_ROCKS_HOST}/{path}'
# Pass method, data, and params from the original request
method = request.method
data = request.data
params = request.args
# Make a request to the new URL with the provided method, data, and params
if method == 'GET':
response = requests.get(chat_ui_url, params=params)
elif method == 'POST':
response = requests.post(chat_ui_url, params=params, data=data)
else:
return Response(status=405, response="Method Not Allowed")
# Create a response with the content received from the new URL
proxied_response = Response(response.content)
proxied_response.status_code = response.status_code
proxied_response.headers["Content-Type"] = "text/html"
return proxied_response
if __name__ == "__main__":
app.run(host="0.0.0.0", port=7860)
|