diff --git a/CHANGELOG.md b/CHANGELOG.md index bc7e9bdcf..fce1c897e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - App visibility: `base44 visibility ` sets it on the server directly (accepts `--app-id` to target any app). Also configurable via `"visibility"` in `config.jsonc`, which `base44 deploy` applies. New projects scaffold `"visibility": "public"`. +### Fixed + +- Newly scaffolded apps talk to the local dev backend under `base44 dev`: the generated client reads the `VITE_BASE44_APP_BASE_URL` env var the dev server injects, falling back to the production server when unset (e.g. plain `npm run dev`). + ## [0.0.51] - 2026-04-28 ### Added diff --git a/packages/cli/templates/backend-and-client/src/api/base44Client.js.ejs b/packages/cli/templates/backend-and-client/src/api/base44Client.js.ejs index c4c0d5967..4eed3f28a 100644 --- a/packages/cli/templates/backend-and-client/src/api/base44Client.js.ejs +++ b/packages/cli/templates/backend-and-client/src/api/base44Client.js.ejs @@ -2,4 +2,8 @@ import { createClient } from '@base44/sdk'; export const base44 = createClient({ appId: '<%= projectId %>', + // `base44 dev` injects VITE_BASE44_APP_BASE_URL (http://localhost:) so the + // SDK targets the local dev backend; unset in prod builds, so it falls back to + // the SDK's default server. + serverUrl: import.meta.env.VITE_BASE44_APP_BASE_URL || undefined, }); diff --git a/packages/cli/tests/cli/create.spec.ts b/packages/cli/tests/cli/create.spec.ts index 0da624d8b..bb243f28f 100644 --- a/packages/cli/tests/cli/create.spec.ts +++ b/packages/cli/tests/cli/create.spec.ts @@ -76,6 +76,34 @@ describe("create command", () => { expect(config).toContain('"visibility": "public"'); }); + it("scaffolds a client that targets the dev server URL injected by base44 dev", async () => { + await t.givenLoggedIn({ email: "test@example.com", name: "Test User" }); + t.api.mockCreateApp({ id: "dev-url-app-id", name: "Dev Url App" }); + + const projectPath = join(t.getTempDir(), "dev-url-app"); + + const result = await t.run( + "create", + "Dev Url App", + "--path", + projectPath, + "--template", + "backend-and-client", + "--no-skills", + ); + + t.expectResult(result).toSucceed(); + + const client = await readFile( + join(projectPath, "src", "api", "base44Client.js"), + "utf-8", + ); + expect(client).toContain("dev-url-app-id"); + expect(client).toContain( + "serverUrl: import.meta.env.VITE_BASE44_APP_BASE_URL || undefined", + ); + }); + it("infers path from name when --path is not provided", async () => { await t.givenLoggedIn({ email: "test@example.com", name: "Test User" }); t.api.mockCreateApp({ id: "inferred-path-id", name: "My App" });