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__.
This commit is contained in:
Kumi 2024-08-03 08:40:59 +02:00
commit c4054c1374
Signed by: kumi
GPG key ID: ECBCC9082395383F
4 changed files with 52 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
venv/
__pycache__/

16
app.py Normal file
View file

@ -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('/<path:url>')
def proxy(url):
jsdelivr_url = f'https://cdn.jsdelivr.net/{url}'
return redirect(jsdelivr_url)
if __name__ == '__main__':
app.run()

1
requirements.txt Normal file
View file

@ -0,0 +1 @@
flask

33
templates/index.html Normal file
View file

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<title>nobsdelivr</title>
<link
href="/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet"
/>
</head>
<body>
<div class="container text-center mt-5">
<h1 class="display-4">Welcome to nobsdelivr</h1>
<p class="lead">
nobsdelivr is a simple proxy to cdn.jsdelivr.net. Use it to proxy your
requests to the CDN.
</p>
<hr class="my-4" />
<p>
To use the proxy, simply replace
<code>https://cdn.jsdelivr.net</code> with <code>{{ domain }}</code> in
the URL.
</p>
<p>Example:</p>
<code>{{ domain }}npm/bootstrap@5.1.3/dist/css/bootstrap.min.css</code>
</div>
<script src="/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>