InstantChat / app.py
cutycat2000x's picture
Update app.py
cfea4a6 verified
raw
history blame
1.21 kB
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)