feat: Switch proxy service from Google Fonts to Typekit

Replaces the existing Google Fonts proxy implementation with support for Typekit, enhancing user privacy.

Updates relevant URLs and regex patterns to handle Typekit requests. Cleans up code by removing unused 'fonts.gstatic.com' proxy endpoint.

Changes references in the HTML template and terminology to reflect the switch from 'GoogleDonts' to 'TypeNot'.

Increases server port for the application from 5678 to 5690.
This commit is contained in:
Kumi 2024-11-25 17:29:03 +01:00
parent 1faf705926
commit 6b82cc7a69
Signed by: kumi
GPG key ID: ECBCC9082395383F
2 changed files with 20 additions and 49 deletions

49
app.py
View file

@ -4,11 +4,12 @@ import re
app = Flask(__name__)
FONT_STATIC_URL = "https://fonts.gstatic.com"
FONT_API_URL = "https://fonts.googleapis.com"
FONT_URL = "https://use.typekit.net"
PATTERN = rb"fonts\.gstatic\.com"
PATTERN = r"use\.typekit\.net"
# P_PATTERN: Any *line* that contains p.typekit.net will be removed
P_PATTERN = r".*p\.typekit\.net.*\n"
@app.route("/")
def home():
@ -16,38 +17,10 @@ def home():
return render_template("index.html", domain=domain)
@app.route("/s/<path:path>", methods=["GET"])
def proxy_fonts_static(path):
url = f"{FONT_STATIC_URL}/s/{path}"
response = requests.get(url, stream=True)
def generate():
for chunk in response.iter_content(chunk_size=8192):
yield chunk
# Remove hop-by-hop headers
headers = {
key: value
for key, value in response.headers.items()
if key.lower()
not in [
"connection",
"keep-alive",
"proxy-authenticate",
"proxy-authorization",
"te",
"trailers",
"transfer-encoding",
"upgrade",
]
}
return Response(generate(), status=response.status_code, headers=headers)
@app.route("/<path:path>", methods=["GET"])
def proxy_fonts_api(path):
def proxy_fonts(path):
query_string = request.query_string.decode("utf-8")
url = f"{FONT_API_URL}/{path}"
url = f"{FONT_URL}/{path}"
if query_string:
url += f"?{query_string}"
headers = {
@ -58,13 +31,11 @@ def proxy_fonts_api(path):
)
response = requests.get(url, headers=headers)
replacement = request.host.encode(
"utf-8"
) # Convert the host to bytes for replacement
if "text/css" in response.headers.get("Content-Type", ""):
content = response.content
content = re.sub(PATTERN, replacement, content)
content = response.content.decode("utf-8")
content = re.sub(PATTERN, request.host, content)
content = re.sub(P_PATTERN, "", content)
headers = {
key: value
@ -103,4 +74,4 @@ def proxy_fonts_api(path):
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5678)
app.run(host="0.0.0.0", port=5690)

View file

@ -6,7 +6,7 @@
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<title>GoogleDonts</title>
<title>TypeNot</title>
<link
href="https://nobsdelivr.private.coffee/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet"
@ -56,22 +56,22 @@
<body>
<header class="hero text-center">
<div class="container">
<h1 class="display-4">Welcome to GoogleDonts</h1>
<h1 class="display-4">Welcome to TypeNot</h1>
<p class="lead">
GoogleDonts is a proxy service to Google Fonts. It allows you to use
Google Fonts without any data being sent to Google.
TypeNot is a privacy-focused proxy for Typekit. It allows you to use
Typekit fonts without giving your visitors' data to Adobe.
</p>
</div>
</header>
<main class="container text-center my-5">
<p class="lead">
To use the proxy, simply replace
<code>https://fonts.googleapis.com/</code> with
<code>https://use.typekit.net/</code> with
<code>{{ domain }}</code> in the URL.
</p>
<p>Example:</p>
<div class="example-code">
<code>{{ domain }}css?family=Montserrat:400,700</code>
<code>{{ domain }}/jjs4qed.css</code>
</div>
</main>
@ -79,9 +79,9 @@
<div class="container">
<h2>Privacy / Disclaimer</h2>
<p>
GoogleDonts is a privacy-focused service. It does not track you or log
any data. It creates a fully separate connection to Google Fonts for
each request, so Google does not see your IP address or any other
TypeNot is a privacy-focused service. It does not track you or log
any data. It creates a fully separate connection to Adobe Fonts for
each request, so Adobe does not see your IP address or any other
information about you.
</p>
<p>
@ -93,7 +93,7 @@
</p>
<p>
The service is open-source and you can view the source code on
<a href="https://git.private.coffee/privatecoffee/googledonts"
<a href="https://git.private.coffee/privatecoffee/typenot"
>Private.coffee Git</a
>.
</p>