diff --git a/ventures/mdecks/tools/whop-check.sh b/ventures/mdecks/tools/whop-check.sh index 628d4d8..68ed88b 100644 --- a/ventures/mdecks/tools/whop-check.sh +++ b/ventures/mdecks/tools/whop-check.sh @@ -1,15 +1,15 @@ #!/bin/sh # Checks the Whop build: builds it, verifies the checksum, unzips it, serves it the way a static host does -# (real files and directory index.html first, 404.html for anything else) and requests the view paths. +# (real files and a directory's index.html first, 404.html for anything else) and requests the view paths. # -# ventures/mdecks/tools/whop-check.sh +# sh ventures/mdecks/tools/whop-check.sh set -eu here=$(cd "$(dirname "$0")" && pwd) work=$(mktemp -d) trap 'rm -rf "$work"' EXIT -"$here/whop-build.sh" "$work/out" +sh "$here/whop-build.sh" "$work/out" (cd "$work/out" && sha256sum -c mdeck-whop.zip.sha256) python3 -c 'import sys, zipfile; zipfile.ZipFile(sys.argv[1]).extractall(sys.argv[2])' "$work/out/mdeck-whop.zip" "$work/site" @@ -19,25 +19,25 @@ import http.server, os, threading, urllib.request, urllib.error site = os.environ["SITE"] class Static(http.server.SimpleHTTPRequestHandler): + """A static host: a real file, or a directory's index.html; anything else gets 404.html with a 404.""" def __init__(self, *a, **k): super().__init__(*a, directory=site, **k) - def send_head(self): - path = self.translate_path(self.path) - if os.path.isdir(path) and not os.path.isfile(os.path.join(path, "index.html")): - path = None - if path is None or not (os.path.isdir(path) or os.path.isfile(path)): - self.path = "/404.html" - self.send_response_only(404) # replaced below - return self._fallback() - return super().send_head() - def _fallback(self): - body = open(os.path.join(site, "404.html"), "rb").read() - self.wfile.write(b"") # status line already sent by send_response_only + def do_GET(self): + bare = self.path.split("?")[0] + path = self.translate_path(bare) + if os.path.isdir(path) and not bare.endswith("/"): + return super().do_GET() # redirect to the slash form + if os.path.isdir(path): + path = os.path.join(path, "index.html") + if os.path.isfile(path): + return super().do_GET() + with open(os.path.join(site, "404.html"), "rb") as f: + body = f.read() + self.send_response(404) self.send_header("Content-Type", "text/html") self.send_header("Content-Length", str(len(body))) self.end_headers() - import io - return io.BytesIO(body) + self.wfile.write(body) def log_message(self, *a): pass @@ -67,7 +67,7 @@ for path, needle in [("/app.js", 'fetch("/SKILL.md")'), ("/whop.js", "data-view" failed += not ok status, body = get("/experiences/abc") -for gone in ("Get early access", "Pricing", "early-note"): +for gone in ("Get early access", "Opens a public GitHub issue", "Pricing", "How it works"): if gone in body: print("public-page content left in the app: " + gone) failed += 1