Skip to content

Commit

Permalink
Let caddy handle https redirection instead of doing it by ourselves
Browse files Browse the repository at this point in the history
Caddy automatically redirects to https, if the domain name qualifies.

https://caddyserver.com/docs/automatic-https#overview
  • Loading branch information
xuhdev committed Jan 5, 2025
1 parent e74744d commit 419074e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 14 deletions.
5 changes: 1 addition & 4 deletions Caddyfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -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)/(.*)$
Expand Down
10 changes: 0 additions & 10 deletions index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 419074e

Please sign in to comment.