1# While the forge is down, the edge serves its pages from the offline copy2# (forge mirror's bucket), and a page the copy leaves out, such as a file's,3# gets the forge's 404 saying so. With caddy installed: the edge's own4# Caddyfile on free ports, the forge's port dead, the bucket a directory5# behind a file server.6. "$(dirname "$0")/../lib.sh"7user dami8repo dami/greet9clone dami dami/greet "$T/w/d"10at "$T/w/d" commit "first" greet.txt11ok push_as dami "$T/w/d" origin main12build13fake_rclone14ok forge mirror15exists "$FORGE_WWW/dami/greet/blob/main/greet.txt/index.html"16command -v caddy >/dev/null 2>&1 || { note "caddy is not installed: skipped running it"; exit 0; }1718mport=$(free_port)19printf '{\n\tadmin off\n\tauto_https off\n\tpersist_config off\n}\n\n:%s {\n\troot * %s\n\tfile_server\n}\n' "$mport" "$T/bucket" >"$T/Caddyfile.bucket"20eport=$(free_port)21dead=$(free_port)22sed "s/^:8080 {/:$eport {/; s/127\.0\.0\.1:8081/127.0.0.1:$dead/" "$T_HOME/deploy/edge/Caddyfile" >"$T/Caddyfile.edge"23for c in bucket edge; do24 FORGE_DOMAIN=src.test FORGE_MIRROR_URL=http://127.0.0.1:$mport XDG_DATA_HOME=$T/xdg XDG_CONFIG_HOME=$T/xdg \25 caddy run --config "$T/Caddyfile.$c" --adapter caddyfile >"$T/caddy.$c.log" 2>&1 &26 T_PIDS="$T_PIDS $!"27done28wait_http "http://127.0.0.1:$mport/"29wait_http "http://127.0.0.1:$eport/"3031http -i -H 'Host: src.test' "http://127.0.0.1:$eport/dami/greet/" >"$T/home"32has "$T/home" '^HTTP/1.1 200 OK'33has "$T/home" '^X-Forge-Offline: mirror'34has "$T/home" 'dami/greet'35http -i -H 'Host: src.test' "http://127.0.0.1:$eport/dami/greet/blob/main/greet.txt/" >"$T/file"36has "$T/file" '^HTTP/1.1 404 Not Found'37has "$T/file" '^Content-Type: text/html; charset=utf-8'38has "$T/file" '^X-Forge-Offline: mirror'39has "$T/file" "isn't in its offline copy"