Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/providers/ipx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { assertEquals } from "jsr:@std/assert";
const absoluteImg = "https://example.com/images/test.jpg";
const img = "/images/test.jpg";
const baseURL = "https://example.com/_ipx";
const remoteBaseUrl = "https://ipx.example.com";


Deno.test("ipx extract", async (t) => {
await t.step("should extract operations from a URL", () => {
Expand Down Expand Up @@ -122,4 +124,19 @@ Deno.test("ipx transform", async (t) => {
`/_ipx/s_300x200,f_auto/https://example.com/images/test.jpg`,
);
});

await t.step("should work with ipx as a remote service baseURL", () => {
const result = transform(
absoluteImg,
{
width: 300,
height: 200,
},
{ baseURL: remoteBaseUrl },
);
assertEqualIgnoringQueryOrder(
result,
`${remoteBaseUrl}/s_300x200,f_auto/https://example.com/images/test.jpg`,
);
});
});
3 changes: 2 additions & 1 deletion src/providers/ipx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import {
createOperationsHandlers,
stripLeadingSlash,
stripTrailingSlash,
toCanonicalUrlString,
toUrl,
} from "../utils.ts";
Expand Down Expand Up @@ -74,7 +75,7 @@ export const generate: URLGenerator<"ipx"> = (
const baseURL = options?.baseURL ?? "/_ipx";
const url = toUrl(baseURL);

url.pathname = `${url.pathname}/${modifiers}/${
url.pathname = `${stripTrailingSlash(url.pathname)}/${modifiers}/${
stripLeadingSlash(src.toString())
}`;
return toCanonicalUrlString(url);
Expand Down