From c4054c1374b101702cbf7d8d8159e1a46799c50e Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 3 Aug 2024 08:40:59 +0200 Subject: [PATCH] feat: add Flask proxy app for cdn.jsdelivr.net Introduce a simple Flask app that proxies requests to cdn.jsdelivr.net. Includes basic routing for home and proxy endpoints, and a template render for the home page explaining usage. Added Flask to requirements.txt and updated .gitignore to exclude venv and __pycache__. --- .gitignore | 2 ++ app.py | 16 ++++++++++++++++ requirements.txt | 1 + templates/index.html | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 .gitignore create mode 100644 app.py create mode 100644 requirements.txt create mode 100644 templates/index.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ea05a1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +venv/ +__pycache__/ \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..6d90845 --- /dev/null +++ b/app.py @@ -0,0 +1,16 @@ +from flask import Flask, redirect, render_template, request + +app = Flask(__name__) + +@app.route('/') +def home(): + domain = request.url_root + return render_template('index.html', domain=domain) + +@app.route('/') +def proxy(url): + jsdelivr_url = f'https://cdn.jsdelivr.net/{url}' + return redirect(jsdelivr_url) + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8ab6294 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +flask \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..8cc4f8d --- /dev/null +++ b/templates/index.html @@ -0,0 +1,33 @@ + + + + + + nobsdelivr + + + +
+

Welcome to nobsdelivr

+

+ nobsdelivr is a simple proxy to cdn.jsdelivr.net. Use it to proxy your + requests to the CDN. +

+
+

+ To use the proxy, simply replace + https://cdn.jsdelivr.net with {{ domain }} in + the URL. +

+

Example:

+ {{ domain }}npm/bootstrap@5.1.3/dist/css/bootstrap.min.css +
+ + +