From b1f5171a3ed341f885a683e0689ea0a9f2674111 Mon Sep 17 00:00:00 2001 From: Netanel Gilad Date: Wed, 18 Mar 2026 11:15:47 +0200 Subject: [PATCH] fix(functions): use app-id-based path for functions.fetch() functions.fetch() was using the domain-based path `/api/functions/{path}` which relies on host-based app resolution. This fails against non-production servers (deploy previews, staging) where the host doesn't map to an app. Switch to the app-id-based path `/api/apps/{appId}/functions/{path}`, matching the pattern invoke() already uses. This makes functions.fetch() work correctly regardless of which server URL is configured. Made-with: Cursor --- src/modules/functions.ts | 2 +- tests/unit/functions.test.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/functions.ts b/src/modules/functions.ts index 1a72c1d..01624b8 100644 --- a/src/modules/functions.ts +++ b/src/modules/functions.ts @@ -86,7 +86,7 @@ export function createFunctionsModule( // Fetch a backend function endpoint directly. async fetch(path: string, init: FunctionsFetchInit = {}) { const normalizedPath = path.startsWith("/") ? path : `/${path}`; - const primaryPath = `/functions${normalizedPath}`; + const primaryPath = `/apps/${appId}/functions${normalizedPath}`; const headers = toHeaders(init.headers); diff --git a/tests/unit/functions.test.ts b/tests/unit/functions.test.ts index 9a55379..06e87c6 100644 --- a/tests/unit/functions.test.ts +++ b/tests/unit/functions.test.ts @@ -468,7 +468,7 @@ describe("Functions Module", () => { expect(fetchMock).toHaveBeenCalledTimes(1); expect(fetchMock).toHaveBeenCalledWith( - `${serverUrl}/api/functions/my_function`, + `${serverUrl}/api/apps/${appId}/functions/my_function`, expect.any(Object) ); }); @@ -498,7 +498,7 @@ describe("Functions Module", () => { fetchMock.mockResolvedValueOnce(new Response("ok", { status: 200 })); await base44.functions.fetch("/my_function"); expect(fetchMock).toHaveBeenCalledWith( - `${serverUrl}/api/functions/my_function`, + `${serverUrl}/api/apps/${appId}/functions/my_function`, expect.any(Object) ); @@ -506,7 +506,7 @@ describe("Functions Module", () => { fetchMock.mockResolvedValueOnce(new Response("ok", { status: 200 })); await base44.functions.fetch("my_function"); expect(fetchMock).toHaveBeenCalledWith( - `${serverUrl}/api/functions/my_function`, + `${serverUrl}/api/apps/${appId}/functions/my_function`, expect.any(Object) ); });