feat: replace redirect with proxy content fetching

Modified the proxy route to fetch and return the content directly from the target URL instead of redirecting. This change leverages `urlopen` to read the response and send its content back to the client, enhancing user experience by keeping them on the same page and avoiding potential CORS issues.
This commit is contained in:
Kumi 2024-08-03 16:26:09 +02:00
parent 8a37bc9f2c
commit 052eeb7531
Signed by: kumi
GPG key ID: ECBCC9082395383F

10
app.py
View file

@ -1,4 +1,6 @@
from flask import Flask, redirect, render_template, request
from flask import Flask, render_template, request
from urllib.request import urlopen
app = Flask(__name__)
@ -10,7 +12,11 @@ def home():
@app.route('/<path:url>')
def proxy(url):
jsdelivr_url = f'https://cdnjs.cloudflare.com/{url}'
return redirect(jsdelivr_url)
response = urlopen(jsdelivr_url)
content = response.read()
return content
if __name__ == '__main__':
app.run()