diff --git a/src/api/client.js b/src/api/client.js index 06964a2..0a01ffb 100644 --- a/src/api/client.js +++ b/src/api/client.js @@ -22,8 +22,9 @@ function isSameOriginBaseUrl(baseUrl) { function buildPathname({ database, kitchenId, path, includeKitchen = true }) { const encodedDatabase = encodeURIComponent(database); - const encodedPathSegments = String(path || '') - .replace(/^\/+/, '') + const rawPath = String(path || '').replace(/^\/+/, ''); + const keepTrailingSlash = rawPath.endsWith('/'); + const encodedPathSegments = rawPath .split('/') .filter(Boolean) .map((segment) => encodeURIComponent(segment)); @@ -35,7 +36,8 @@ function buildPathname({ database, kitchenId, path, includeKitchen = true }) { segments.push(...encodedPathSegments); - return `/${segments.join('/')}`; + const pathname = `/${segments.join('/')}`; + return keepTrailingSlash ? `${pathname}/` : pathname; } function buildUrl({ baseUrl, database, kitchenId, path, query = {}, includeKitchen = true }) {