diff --git a/src/providers/ipx.test.ts b/src/providers/ipx.test.ts index c1f6ed8..985d5c7 100644 --- a/src/providers/ipx.test.ts +++ b/src/providers/ipx.test.ts @@ -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", () => { @@ -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`, + ); + }); }); diff --git a/src/providers/ipx.ts b/src/providers/ipx.ts index d1fce56..978259a 100644 --- a/src/providers/ipx.ts +++ b/src/providers/ipx.ts @@ -8,6 +8,7 @@ import { import { createOperationsHandlers, stripLeadingSlash, + stripTrailingSlash, toCanonicalUrlString, toUrl, } from "../utils.ts"; @@ -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);