From 052eeb753114cdef6abb89affd65a2114276112d Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 3 Aug 2024 16:26:09 +0200 Subject: [PATCH] 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. --- app.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 79d3858..5ff6eed 100644 --- a/app.py +++ b/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('/') 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() \ No newline at end of file