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:
parent
8a37bc9f2c
commit
052eeb7531
1 changed files with 8 additions and 2 deletions
10
app.py
10
app.py
|
@ -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()
|
Loading…
Reference in a new issue