feat: Add version to curl response
All checks were successful
Build Docker / BuildImage (push) Successful in 1m12s

This commit is contained in:
2025-06-20 22:14:22 +10:00
parent 159a40ecb5
commit a79c795672

View File

@@ -132,6 +132,22 @@ def getClientIP(request):
ip = request.remote_addr ip = request.remote_addr
return ip return ip
def getVersion():
# if .git exists, get the latest commit hash
if os.path.isdir(".git"):
git_dir = ".git"
head_ref = ""
with open(os.path.join(git_dir, "HEAD")) as file:
head_ref = file.read().strip()
if head_ref.startswith("ref: "):
head_ref = head_ref[5:]
with open(os.path.join(git_dir, head_ref)) as file:
return file.read().strip()
else:
return head_ref
return "failed to get version"
# region Special routes # region Special routes
@app.route("/meet") @app.route("/meet")
@@ -504,6 +520,7 @@ def index():
"message": "Welcome to Nathan.Woodburn/! This is a personal website. For more information, visit https://nathan.woodburn.au", "message": "Welcome to Nathan.Woodburn/! This is a personal website. For more information, visit https://nathan.woodburn.au",
"ip": getClientIP(request), "ip": getClientIP(request),
"dev": handshake_scripts == "", "dev": handshake_scripts == "",
"version": getVersion()
} }
) )