From d4dae6ca4fa5db348a012dc569b61e329e2f7c42 Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Sun, 5 Jan 2025 12:10:08 -0800 Subject: [PATCH] Let caddy handle https redirection instead of doing it by ourselves (#7) Caddy automatically redirects to https, if the domain name qualifies. Some hosting services already lays a front layer with https, which the current configuration would break. https://caddyserver.com/docs/automatic-https#overview --- Caddyfile.base | 5 +---- index.test.ts | 10 ---------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/Caddyfile.base b/Caddyfile.base index ec8c2b9..b1828f7 100644 --- a/Caddyfile.base +++ b/Caddyfile.base @@ -18,10 +18,7 @@ admin off } -{$DOMAIN:localhost}:80 { - redir https://{host}{uri} permanent -} - +{$DOMAIN:localhost}:80, {$DOMAIN:localhost}:443 { redir /abc https://example.com @snapshot path_regexp ^/snapshot/(\d\d\d\d-\d\d-\d\d)/(.*)$ diff --git a/index.test.ts b/index.test.ts index e567681..63d377c 100644 --- a/index.test.ts +++ b/index.test.ts @@ -20,16 +20,6 @@ const domain = "localhost" as const; const delpaGitHubRawBaseUrl = "https://raw.githubusercontent.com/delpa-org" as const; -test("Redirect http to https", async () => { - const hostAddress = `http://${domain}:3000`; - const response = await fetch(`${hostAddress}/some/path`, { - redirect: "manual", - }); - - expect(response.status).toBe(301); - expect(response.headers.get("location")).toBe(`https://${domain}/some/path`); -}); - describe("/snapshot", () => { const hostAddress = `https://${domain}:3001`; const snapshotFirstPathComp = "snapshot" as const;