Spaces:
Running
Running
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' | |
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 | |
headers = None | |
# If the request is a POST request, set the Content-Type header to application/json | |
if method == 'POST': | |
headers = {'Content-Type': 'application/json'} | |
# Make a request to the new URL with the provided method, data, params, and headers | |
response = requests.request(method, chat_ui_url, params=params, data=data, headers=headers) | |
# 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) | |