feat: Add README and dynamic port configuration

Introduces a README with setup and usage instructions for the GoogleDonts app, enhancing accessibility and guidance for users.

Adapts the app to use an environment variable for port configuration, allowing flexibility in deployment environments, which defaults to port 5678 when unset.

Refactors request headers to exclude "Accept-Encoding", ensuring compatibility with font responses.

This update aims to support user autonomy in hosting and increase privacy assurance.

Relates to potential improvements in user deployment experiences and privacy measures.
This commit is contained in:
Kumi 2024-11-27 12:50:44 +01:00
parent 1faf705926
commit 5a4d3aa9e7
Signed by: kumi
GPG key ID: ECBCC9082395383F
2 changed files with 49 additions and 5 deletions

46
README.md Normal file
View file

@ -0,0 +1,46 @@
# GoogleDonts - a privacy-friendly Google Fonts proxy
GoogleDonts is a Flask app that acts as a proxy for Google Fonts. It allows you to use fonts without disclosing your website visitors' IP addresses to Google.
## How it works
GoogleDonts works by fetching the font files from Google and serving them to the client. This way, the client's IP address is never disclosed to Google. It does not store any data about the client.
It modifies the CSS files so that the font URLs also point to the proxy. This way, the client's browser fetches the font files from the proxy instead of Google.
### Disclaimer
We try our best to ensure that users do not make any connections to Google's servers. However, we cannot guarantee that we catch everything. If you find any issues, please report them. And if at all possible, please host your own fonts instead of using Google Fonts.
## Setup
1. Clone the repository
```bash
git clone https://git.private.coffee/PrivateCoffee/googledonts.git
cd googledonts
```
2. Create a virtual environment and install the dependencies
```bash
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```
3. Use the flask command or a WSGI server to run the app
```bash
flask run
```
In production, you should use a WSGI server like uWSGI, and a reverse proxy like Caddy. Ensure that your server does not log the client's IP address!
## Configuration
GoogleDonts does not require any configuration. However, if you use `flask run`, you can set the `PORT` environment variable to change the port the app listens on. By default, it listens on port 5678.
## License
TypeNot is licensed under the MIT License. See [LICENSE](LICENSE) for more information.

8
app.py
View file

@ -1,6 +1,7 @@
from flask import Flask, request, Response, render_template
import requests
import re
import os
app = Flask(__name__)
@ -51,11 +52,8 @@ def proxy_fonts_api(path):
if query_string:
url += f"?{query_string}"
headers = {
key: value for (key, value) in request.headers.items() if key.lower() != "host"
"Accept-Encoding": ""
}
headers["Accept-Encoding"] = (
"" # Disable Accept-Encoding to avoid compressed responses
)
response = requests.get(url, headers=headers)
replacement = request.host.encode(
@ -103,4 +101,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=os.environ.get("PORT", 5678))