From 60d898738c15a06a757e641b00a25c7b0057dcc3 Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Sun, 5 Jan 2025 12:45:50 -0800 Subject: [PATCH] Add health-check path (#9) --- Caddyfile.base | 4 +++- index.test.ts | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Caddyfile.base b/Caddyfile.base index cdf344a..442d679 100644 --- a/Caddyfile.base +++ b/Caddyfile.base @@ -19,9 +19,11 @@ } {$HOST_ADDRESS:localhost} { - redir /abc https://example.com + respond /health-check "OK" + @snapshot path_regexp ^/snapshot/(\d\d\d\d-\d\d-\d\d)/(.*)$ redir @snapshot https://raw.githubusercontent.com/delpa-org/melpa-snapshot-{re.1}/refs/heads/master/packages/{re.2} permanent + respond "404 Not Found" 404 { close } diff --git a/index.test.ts b/index.test.ts index 63d377c..c08b4e8 100644 --- a/index.test.ts +++ b/index.test.ts @@ -16,12 +16,19 @@ * along with this program. If not, see . */ -const domain = "localhost" as const; +const hostAddress = "https://localhost:3001" as const; const delpaGitHubRawBaseUrl = "https://raw.githubusercontent.com/delpa-org" as const; +test("/health-check", async () => { + const response = await fetch(`${hostAddress}/health-check`, { + redirect: "manual", + }); + expect(response.status).toBe(200); + expect(await response.text()).toBe("OK"); +}); + describe("/snapshot", () => { - const hostAddress = `https://${domain}:3001`; const snapshotFirstPathComp = "snapshot" as const; for (const [name, path] of [ ["valid with a one-level subdir", "2025-01-02/a"],