Kumi
052eeb7531
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.
22 lines
No EOL
453 B
Python
22 lines
No EOL
453 B
Python
from flask import Flask, render_template, request
|
|
|
|
from urllib.request import urlopen
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route('/')
|
|
def home():
|
|
domain = request.url_root
|
|
return render_template('index.html', domain=domain)
|
|
|
|
@app.route('/<path:url>')
|
|
def proxy(url):
|
|
jsdelivr_url = f'https://cdnjs.cloudflare.com/{url}'
|
|
|
|
response = urlopen(jsdelivr_url)
|
|
content = response.read()
|
|
|
|
return content
|
|
|
|
if __name__ == '__main__':
|
|
app.run() |