Skip to content

Commit 50858bb

Browse files
committed
Prefix snapshot with /melpa/
In case of future support of (non-)GNU Elpa.
1 parent 9ffa223 commit 50858bb

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

gen_caddy.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import snapshotVersions from "./melpa_snapshot_versions.json" with { type: "json" };
2222

23+
const melpaSnapshotLeadingComp = "/melpa/snapshot" as const;
2324
const snapshotVersionsRegexp = snapshotVersions.join("|");
2425

2526
const caddyfile = `
@@ -38,16 +39,16 @@ const caddyfile = `
3839
close
3940
}
4041
41-
route /snapshot/* {
42-
@valid-snapshot-root path_regexp ^/snapshot/(${snapshotVersionsRegexp})/*$
42+
route ${melpaSnapshotLeadingComp}/* {
43+
@valid-snapshot-root path_regexp ^${melpaSnapshotLeadingComp}/(${snapshotVersionsRegexp})/*$
4344
respond @valid-snapshot-root 200 {
4445
body "{re.1} is a valid snapshot version."
4546
close
4647
}
47-
@valid-snapshot path_regexp ^/snapshot/(${snapshotVersionsRegexp})/(.*)$
48+
@valid-snapshot path_regexp ^${melpaSnapshotLeadingComp}/(${snapshotVersionsRegexp})/(.*)$
4849
redir @valid-snapshot https://raw.githubusercontent.com/delpa-org/melpa-snapshot-{re.1}/refs/heads/master/packages/{re.2} permanent
4950
50-
@invalid-snapshot path_regexp ^/snapshot/([^/]+).*$
51+
@invalid-snapshot path_regexp ^${melpaSnapshotLeadingComp}/([^/]+).*$
5152
respond @invalid-snapshot 404 {
5253
5354
body "404 Not Found. Invalid snapshot version: {re.1}

index.test.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ test("/health-check returns 200 with OK", async () => {
3636
expect(await response.text()).toBe("OK");
3737
});
3838

39-
describe("/snapshot", () => {
40-
const snapshotFirstPathComp = "snapshot" as const;
39+
describe("/melpa/snapshot", () => {
40+
const snapshotLeadingPathComp = "melpa/snapshot" as const;
4141
for (const [name, path] of [
4242
["valid with a one-level subdir", "2024-01-01/a/b"],
4343
["valid with a one-level subdir with a trailing slash", "2024-02-02/a/b/"],
@@ -49,7 +49,7 @@ describe("/snapshot", () => {
4949
] as const) {
5050
test(`Redirect with valid URL under /shapshot: ${name}`, async () => {
5151
const response = await fetch(
52-
`${hostAddress}/${snapshotFirstPathComp}/${path}`,
52+
`${hostAddress}/${snapshotLeadingPathComp}/${path}`,
5353
{
5454
redirect: "manual",
5555
},
@@ -70,9 +70,9 @@ describe("/snapshot", () => {
7070
["without a trailing slash", "2024-01-01"],
7171
["with a trailing slash", "2024-02-02/"],
7272
] as const) {
73-
test(`Report OK with valid snapshot version at a root dir of /shapshot: ${name}`, async () => {
73+
test(`Report OK with valid snapshot version at a root dir of /melpa/shapshot: ${name}`, async () => {
7474
const response = await fetch(
75-
`${hostAddress}/${snapshotFirstPathComp}/${path}`,
75+
`${hostAddress}/${snapshotLeadingPathComp}/${path}`,
7676
{
7777
redirect: "manual",
7878
},
@@ -101,9 +101,9 @@ describe("/snapshot", () => {
101101
"non-existing/a/b/",
102102
],
103103
] as const) {
104-
test(`Return 404 with invalid URL under /shapshot: ${name}`, async () => {
104+
test(`Return 404 with invalid URL under /melpa/shapshot: ${name}`, async () => {
105105
const response = await fetch(
106-
`${hostAddress}/${snapshotFirstPathComp}/${path}`,
106+
`${hostAddress}/${snapshotLeadingPathComp}/${path}`,
107107
{
108108
redirect: "manual",
109109
},

prod.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ test("/health-check returns 200 with OK", async () => {
4343
expect(await response.text()).toBe("OK");
4444
});
4545

46-
describe("/snapshot", () => {
47-
const snapshotFirstPathComp = "snapshot" as const;
48-
test("Redirect with valid URL under /shapshot", async () => {
46+
describe("/melpa/snapshot", () => {
47+
const snapshotLeadingPathComp = "/melpa/snapshot" as const;
48+
test("Redirect with valid URL under /melpa/shapshot", async () => {
4949
const response = await fetch(
50-
`${hostAddress}/${snapshotFirstPathComp}/2025-01-02/subpath`,
50+
`${hostAddress}/${snapshotLeadingPathComp}/2025-01-02/subpath`,
5151
{
5252
redirect: "manual",
5353
},
@@ -62,7 +62,7 @@ describe("/snapshot", () => {
6262

6363
test("Report OK with valid snapshot version at a root dir of /shapshot", async () => {
6464
const response = await fetch(
65-
`${hostAddress}/${snapshotFirstPathComp}/2025-01-02`,
65+
`${hostAddress}/${snapshotLeadingPathComp}/2025-01-02`,
6666
{
6767
redirect: "manual",
6868
},
@@ -76,7 +76,7 @@ describe("/snapshot", () => {
7676

7777
test("Return 404 with invalid URL under /shapshot", async () => {
7878
const response = await fetch(
79-
`${hostAddress}/${snapshotFirstPathComp}/non-existing`,
79+
`${hostAddress}/${snapshotLeadingPathComp}/non-existing`,
8080
{
8181
redirect: "manual",
8282
},

0 commit comments

Comments
 (0)