nocdnbs/app.py
Kumi 052eeb7531
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.
2024-08-03 16:26:09 +02:00

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()