Skip to content

fix: normalize IMMICH_BASE_URL to always include /api prefix - #9

Open
rokelvisar wants to merge 1 commit into
lidless-labs:masterfrom
rokelvisar:master
Open

fix: normalize IMMICH_BASE_URL to always include /api prefix#9
rokelvisar wants to merge 1 commit into
lidless-labs:masterfrom
rokelvisar:master

Conversation

@rokelvisar

@rokelvisar rokelvisar commented Jul 26, 2026

Copy link
Copy Markdown

Problem

Immich v3 moved all API routes under /api/* (e.g. /api/search/smart, /api/search/metadata). Users commonly set IMMICH_BASE_URL to just the server origin (e.g. https://photos.example.com) without the /api suffix, causing 404 errors on SDK calls.

The SDK defaults to baseUrl: "/api", but when the user provides https://photos.example.com, that value replaces the default — so the SDK constructs https://photos.example.com/search/smart instead of https://photos.example.com/api/search/smart.

Fix

Added normalizeBaseUrl() in src/config.ts that:

  1. Strips trailing slashes
  2. Appends /api if the URL does not already end with it

Applied in getConfig() so both https://photos.example.com and https://photos.example.com/api work correctly.

Examples

Input Output
https://photos.example.com https://photos.example.com/api
https://photos.example.com/ https://photos.example.com/api
https://photos.example.com/api https://photos.example.com/api
http://localhost:2283 http://localhost:2283/api

Verification

  • Build passes (npm run build)
  • All 243 existing tests pass
  • 6 new tests cover normalizeBaseUrl edge cases
  • Tested live against Immich v3.0.3 — search, assets, albums all work with bare origin URL

Immich v3 requires all API routes under /api/* (e.g. /api/search/smart).
Users commonly set IMMICH_BASE_URL to just the server origin
(https://photos.example.com) without /api suffix, causing 404 errors
on search, asset listing, and other SDK calls.

Add normalizeBaseUrl() that appends /api if missing, so both
configurations work correctly.
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.

2 participants