Skip to content

feat(pwa): derive API base from runtime host by default#10

Merged
sergdort merged 3 commits intomainfrom
feat/pwa-runtime-api-base
Mar 3, 2026
Merged

feat(pwa): derive API base from runtime host by default#10
sergdort merged 3 commits intomainfrom
feat/pwa-runtime-api-base

Conversation

@LogenNineFingersIsAlive
Copy link
Collaborator

@LogenNineFingersIsAlive LogenNineFingersIsAlive commented Mar 3, 2026

Summary

  • resolve PWA API base at runtime from the current browser host when VITE_API_BASE is not configured
  • keep explicit VITE_API_BASE override support for custom environments
  • update web runtime env injection to avoid forcing a fallback VITE_API_BASE when not configured (while still rewriting when --api-port is explicitly set)

Why

Tailnet/local host changes were causing stale baked API base URLs in the PWA preview bundle, resulting in loading spinners when the API host changed. This makes host selection resilient by default while preserving explicit env control.

Validation

  • biome checks for changed files
  • pnpm --filter @tithe/tests test -- tests/cli/web.spec.ts
  • pnpm --filter @tithe/pwa build

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the PWA + CLI web runtime so the API base URL is resolved at runtime from the browser host by default (when VITE_API_BASE is not set), avoiding stale baked-in API URLs across host changes while keeping explicit overrides.

Changes:

  • PWA: resolve API base URL from window.location when VITE_API_BASE is unset, with normalization for configured values.
  • CLI: adjust web runtime env injection so VITE_API_BASE is only injected when explicitly configured or when --api-port is provided.
  • Vite preview: allow preview hostnames for localhost and Tailnet (.ts.net).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
apps/pwa/vite.config.ts Adds preview.allowedHosts to support localhost/Tailnet preview access.
apps/pwa/src/api.ts Introduces runtime API base URL resolution (env override + browser-host-derived fallback).
apps/cli/src/web.ts Stops forcing a fallback VITE_API_BASE into the PWA runtime env unless --api-port is set.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sergdort sergdort merged commit fbe69ef into main Mar 3, 2026
1 check passed
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.

3 participants