Homepage (TDD slice 7): fix the /admin/ path + status.json perms
Two real bugs found on the first production deploy: - /admin/ 404'd: file_server looked for /srv/homepage/admin/ (a dir), but the page is admin.html. Add '@admin rewrite * /admin.html' so the /admin/ path serves admin.html. - The pages used relative refs (style.css, app.js, services.json, status.json), which from /admin/ resolved to /admin/... (404). Add <base href="/"> so all refs resolve to the site root on both pages. - status.json was written 0600 (root); the checker now chmods it 0644 so Caddy can serve it regardless of its user.
This commit is contained in:
@@ -54,6 +54,7 @@ dankclaw.franksdank.cloud {
|
||||
basicauth @admin {
|
||||
frank REPLACE_WITH_ADMIN_HASH
|
||||
}
|
||||
@admin rewrite * /admin.html
|
||||
root * /srv/homepage
|
||||
file_server
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ def main(argv):
|
||||
with os.fdopen(fd, "w") as f:
|
||||
json.dump(doc, f)
|
||||
os.replace(tmp, out_path)
|
||||
os.chmod(out_path, 0o644) # world-readable so Caddy can serve it
|
||||
except Exception:
|
||||
if os.path.exists(tmp):
|
||||
os.unlink(tmp)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>frank — admin</title>
|
||||
<base href="/">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>frank — services</title>
|
||||
<base href="/">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -24,3 +24,7 @@ setup() {
|
||||
grep -q "root \* /srv/homepage" "$CADDY"
|
||||
grep -q "file_server" "$CADDY"
|
||||
}
|
||||
|
||||
@test "the /admin/ path is rewritten to admin.html" {
|
||||
grep -qE "@admin[[:space:]]+rewrite[[:space:]]+\*[[:space:]]+/admin.html" "$CADDY"
|
||||
}
|
||||
|
||||
@@ -88,3 +88,10 @@ assert s["realhttp"] == "up", s
|
||||
PY
|
||||
kill "$RAW_PID" "$HTTP_PID" 2>/dev/null
|
||||
}
|
||||
|
||||
@test "the checker writes status.json world-readable so Caddy can serve it" {
|
||||
local svc="$TMP/services.json" out="$TMP/status.json"
|
||||
echo '[{"name":"x","category":"user","probe":"127.0.0.1:1","method":"tcp","wip":true}]' > "$svc"
|
||||
python3 "$CHECKER" "$svc" "$out"
|
||||
[ "$(stat -c %a "$out")" = "644" ]
|
||||
}
|
||||
|
||||
@@ -43,3 +43,8 @@ setup() {
|
||||
grep -q "deployed-at" "$BASE/admin.html"
|
||||
grep -q "deployed-at" "$BASE/app.js"
|
||||
}
|
||||
|
||||
@test "the pages set a base so the /admin/ page resolves refs to the root" {
|
||||
grep -q '<base href="/">' "$BASE/index.html"
|
||||
grep -q '<base href="/">' "$BASE/admin.html"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user