Skip to content

fix(dev): scaffold apps with the injected local dev server URL - #571

Closed
davidsu wants to merge 2 commits into
mainfrom
fix/dev-template-server-url
Closed

fix(dev): scaffold apps with the injected local dev server URL#571
davidsu wants to merge 2 commits into
mainfrom
fix/dev-template-server-url

Conversation

@davidsu

@davidsu davidsu commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Note

Description

Newly scaffolded backend-and-client apps hardcoded no serverUrl, so the generated @base44/sdk client always talked to the production Base44 server — even when running under base44 dev, which spins up a local backend. This PR makes the scaffolded client read the VITE_BASE44_APP_BASE_URL env var that the dev server already injects into the site.serveCommand process, falling back to the SDK default when the var is unset (plain npm run dev, production builds). No CLI code changes are needed; the dev server already exports the variable in packages/cli/src/cli/dev/dev-server/main.ts.

Related Issue

None

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Other (please describe):

Changes Made

  • packages/cli/templates/backend-and-client/src/api/base44Client.js.ejs: pass serverUrl: import.meta.env.VITE_BASE44_APP_BASE_URL || undefined to createClient(), with a comment explaining the dev-vs-prod behavior.
  • packages/cli/tests/cli/create.spec.ts: new integration test asserting that base44 create --template backend-and-client scaffolds src/api/base44Client.js containing both the app id and the serverUrl env-var read.
  • CHANGELOG.md: added a ### Fixed entry under the unreleased section.

Testing

  • I have tested these changes locally
  • I have added/updated tests as needed
  • All tests pass (npm test)

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (if applicable)
  • My changes generate no new warnings
  • I have updated docs/ (AGENTS.md) if I made architectural changes

Additional Notes

The fallback is || undefined rather than an empty string so the SDK applies its own default server URL instead of receiving a falsy override. Only the backend-and-client template is affected; other templates do not generate an SDK client. The test suite was not executed in this environment (build/test commands were unavailable), so the "tested locally" and "all tests pass" boxes are left unchecked pending CI.


🤖 Generated by Claude | 2026-07-27 09:01 UTC | 7e17867

@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

🚀 Package Preview Available!


Install this PR's preview build with npm:

npm i @base44-preview/cli@0.1.5-pr.571.7e17867

Prefer not to change any import paths? Install using npm alias so your code still imports base44:

npm i "base44@npm:@base44-preview/cli@0.1.5-pr.571.7e17867"

Or add it to your package.json dependencies:

{
  "dependencies": {
    "base44": "npm:@base44-preview/cli@0.1.5-pr.571.7e17867"
  }
}

Preview published to npm registry — try new features instantly!

davidsu and others added 2 commits July 27, 2026 11:58
`base44 dev` injects VITE_BASE44_APP_BASE_URL so the app's SDK targets the
local dev backend, but the scaffolded base44Client only passed { appId }, so
the browser hit the remote backend instead of localhost. Pass serverUrl from
the injected env var; it is unset in prod builds, so the SDK falls back to its
default server.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Also add a changelog entry for the template fix.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@davidsu
davidsu force-pushed the fix/dev-template-server-url branch from 8e6eea5 to fb3842a Compare July 27, 2026 09:01
@davidsu

davidsu commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on main and extended: added a create-command test asserting the scaffolded client reads VITE_BASE44_APP_BASE_URL, plus a changelog entry.

Context from today's investigation: this is the missing half of the env-var contract — base44 dev injects the URL (dev-server/main.ts) but nothing in the scaffold consumed it, so scaffolded FEs always talked to prod. Editor-created apps already work via @base44/vite-plugin's /api proxy (serverUrl: '' + proxy); this PR gives CLI-scaffolded apps the equivalent, while || undefined keeps plain npm run dev working against prod. Verified the editor-app mechanism end-to-end on a real app this morning.

@davidsu

davidsu commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Superseded — closing per today's design decision. The approach changed from a direct env-var read in the template to converging the scaffold onto the editor-app convention: serverUrl: '' + @base44/vite-plugin (whose /api dev proxy consumes the same VITE_BASE44_APP_BASE_URL that base44 dev injects). Sequence: a vite-plugin PR ships standalone-dev fallbacks first (no broken npm run dev window), then a fresh template-convergence PR lands here pinned to the released plugin version. Context: suss-tasks/local_dev_parity/ in this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant