From 6ae6909f989a6bc57f2c83375577f7694473be1e Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Mon, 21 Apr 2025 13:16:06 +1000 Subject: [PATCH] Add redirects for `install.qmk.fm`, `api.qmk.fm/install.sh`. --- web.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/web.py b/web.py index 8e1a597..4eddb7d 100644 --- a/web.py +++ b/web.py @@ -6,6 +6,7 @@ from os.path import exists from os import stat, remove, makedirs, environ from time import strftime, time, localtime +from urllib.parse import urlparse import graphyte import requests @@ -131,6 +132,12 @@ def client_ip(): return request.headers.get('X-Forwarded-For', request.remote_addr) +def request_hostname(): + """Returns the hostname of the request. + """ + return urlparse(request.base_url).hostname + + def error(message, code=400, **kwargs): """Return a structured JSON error message. """ @@ -251,9 +258,18 @@ def kle_to_qmk(kle): def root(): """Serve up the documentation for this API. """ + if request_hostname() == 'install.qmk.fm': + return redirect('https://raw.githubusercontent.com/qmk/qmk_firmware/refs/heads/bootstrap/util/env-bootstrap.sh') return redirect('https://docs.qmk.fm/#/api_docs') +@app.route('/install.sh', methods=['GET']) +def install(): + """Serve up the install script for the QMK CLI. + """ + return redirect('https://raw.githubusercontent.com/qmk/qmk_firmware/refs/heads/bootstrap/util/env-bootstrap.sh') + + @app.route('/v1', methods=['GET']) def GET_v1(): """Return the API's status.