Skip to content

Commit 1a3c669

Browse files
authored
fix(ipx): make ipx transform work with a remote base url (#173)
* fix: Make ipx transform work with a remote base url * fix: use stripTrailingSlash
1 parent 1f67e59 commit 1a3c669

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/providers/ipx.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { assertEquals } from "jsr:@std/assert";
55
const absoluteImg = "https://example.com/images/test.jpg";
66
const img = "/images/test.jpg";
77
const baseURL = "https://example.com/_ipx";
8+
const remoteBaseUrl = "https://ipx.example.com";
9+
810

911
Deno.test("ipx extract", async (t) => {
1012
await t.step("should extract operations from a URL", () => {
@@ -122,4 +124,19 @@ Deno.test("ipx transform", async (t) => {
122124
`/_ipx/s_300x200,f_auto/https://example.com/images/test.jpg`,
123125
);
124126
});
127+
128+
await t.step("should work with ipx as a remote service baseURL", () => {
129+
const result = transform(
130+
absoluteImg,
131+
{
132+
width: 300,
133+
height: 200,
134+
},
135+
{ baseURL: remoteBaseUrl },
136+
);
137+
assertEqualIgnoringQueryOrder(
138+
result,
139+
`${remoteBaseUrl}/s_300x200,f_auto/https://example.com/images/test.jpg`,
140+
);
141+
});
125142
});

src/providers/ipx.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import {
99
createOperationsHandlers,
1010
stripLeadingSlash,
11+
stripTrailingSlash,
1112
toCanonicalUrlString,
1213
toUrl,
1314
} from "../utils.ts";
@@ -74,7 +75,7 @@ export const generate: URLGenerator<"ipx"> = (
7475
const baseURL = options?.baseURL ?? "/_ipx";
7576
const url = toUrl(baseURL);
7677

77-
url.pathname = `${url.pathname}/${modifiers}/${
78+
url.pathname = `${stripTrailingSlash(url.pathname)}/${modifiers}/${
7879
stripLeadingSlash(src.toString())
7980
}`;
8081
return toCanonicalUrlString(url);

0 commit comments

Comments
 (0)