Skip to content

fix: honor configured base for dev authoring APIs - #393

Open
iddogino wants to merge 1 commit into
1weiho:mainfrom
iddogino:fix/dev-api-base-path
Open

fix: honor configured base for dev authoring APIs#393
iddogino wants to merge 1 commit into
1weiho:mainfrom
iddogino:fix/dev-api-base-path

Conversation

@iddogino

@iddogino iddogino commented Aug 5, 2026

Copy link
Copy Markdown

Fixes #392

When OpenSlideConfig.base is a non-root path, the UI renders fine beneath the base but all dev authoring APIs break: the client issues root-absolute fetch('/__folders')-style requests that escape the mount behind a reverse proxy, and the Connect middleware is only registered at root paths, so requests arriving as /<base>/__* fall through to Vite's SPA HTML handling.

Changes

Client — new devApiUrl() helper in app/lib/dev-api.ts joins import.meta.env.BASE_URL (the same signal #173/#207 used for the router basename and presenter URLs) with the dev API path. Every /__* fetch across folders, slides, editing, notes, comments, design, assets, svgl, update, and restart now goes through it, as do the constructed asset/svgl proxy URLs used as image sources.

Server — new mountDevRoute() / devRoutePaths() helpers in vite/routes/mount.ts read the resolved server.config.base and mount each route beneath the base first, keeping the root mount for direct probes and pre-base clients (with base: '/' registration is unchanged — a single root mount). Used by all routes/* registrations plus the design and notes plugins. Asset URLs embedded in JSON responses are base-prefixed via withBase().

Tests (written first, TDD)

  • vite/routes/base-routing.test.ts — HTTP-level reproduction of the issue over a connect-style mount stack: with base: '/my-slides/', GET /my-slides/__folders previously fell through to text/html (the exact failure in the report) and now returns application/json; root probes and SPA fallback for non-API paths still behave. Plus a route-inventory sweep asserting every dev API route group (including /__design and /__notes) mounts both beneath a nested base and at root.
  • vite/routes/mount.test.ts — unit coverage for devRoutePaths/withBase/mountDevRoute across /, nested, trailing-slash-less, deep, and relative bases.
  • app/lib/dev-api.test.tsjoinBase/devApiUrl under BASE_URL='/' and '/my-slides/' (via vi.stubEnv), plus a source scan guarding against future root-absolute fetch('/__…') call sites in src/app.

Red run before the fix: the nested-base routing test failed with expected 'text/html' to contain 'application/json'; after the fix all 329 tests pass. pnpm typecheck and pnpm check are clean, and a changeset (patch, @open-slide/core) is included.

Summary by CodeRabbit

  • Bug Fixes

    • Development APIs now work correctly when the application is hosted under a custom or nested base path.
    • Asset URLs and development tools—including editing, comments, notes, designs, folders, slides, updates, and server controls—now resolve reliably in subpath deployments.
  • Tests

    • Added coverage for root and nested base paths, route mounting, asset URLs, and development API requests.

Client /__* fetches now go through a devApiUrl() helper built on
import.meta.env.BASE_URL, and server routes are mounted beneath the
resolved base (keeping the root mounts for direct probes), so folder
mutations, inline editing, notes, comments, assets, and server actions
work when OpenSlide is hosted at a subpath.

Fixes 1weiho#392

Claude-Session: https://claude.ai/code/session_01Gu3Kz4JQBFc6kKkAfEoXCq
@vercel

vercel Bot commented Aug 5, 2026

Copy link
Copy Markdown

@iddogino is attempting to deploy a commit to the open-slide Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Development API clients now build URLs from import.meta.env.BASE_URL. Vite development routes mount under configured bases and at root fallback paths. Tests cover URL joining, route registration, nested-base requests, and direct root-absolute API calls.

Changes

Base-aware development API routing

Layer / File(s) Summary
Development API URL helper and coverage
packages/core/src/app/lib/dev-api.ts, packages/core/src/app/lib/dev-api.test.ts
Added joinBase and devApiUrl. Tests cover root, nested, relative, trailing-slash, and query-string bases.
Application request migration
packages/core/src/app/components/..., packages/core/src/app/lib/..., packages/core/src/app/routes/slide.tsx, .changeset/brave-paths-follow.md
Updated development API requests and generated asset URLs to use devApiUrl. Added a patch changeset.
Vite route mounting
packages/core/src/vite/routes/mount.ts, packages/core/src/vite/routes/*.ts, packages/core/src/vite/*-plugin.ts
Added withBase, devRoutePaths, and mountDevRoute. Development routes now register under configured bases and root fallback paths. Asset response URLs include the configured base.
Routing integration tests
packages/core/src/vite/routes/*test.ts
Added tests for middleware registration, nested-base requests, root fallback mounts, route inventory, and SPA fallback behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers: 1weiho

Poem

A rabbit checks each path with care,
Through nested roots and routes laid bare.
APIs hop where bases guide,
Vite mounts both side by side.
Tests keep every burrow bright.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.20% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: honoring the configured base path for development authoring APIs.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/core/src/vite/routes/svgl.ts (1)

5-6: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the endpoint-description comments.

These comments describe behavior. They do not document a non-obvious constraint or invariant. As per coding guidelines, "**/*.{ts,tsx,js,jsx}: Default to writing no comments. Only add one when the WHY is non-obvious`."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/core/src/vite/routes/svgl.ts` around lines 5 - 6, Remove the
endpoint-description comments above the route implementation in the svgl module,
leaving the route behavior and surrounding code unchanged.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/core/src/vite/routes/svgl.ts`:
- Around line 5-6: Remove the endpoint-description comments above the route
implementation in the svgl module, leaving the route behavior and surrounding
code unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c0e706a0-35b8-4155-8aee-36d705e66b95

📥 Commits

Reviewing files that changed from the base of the PR and between 2dc2b91 and d24941b.

📒 Files selected for processing (26)
  • .changeset/brave-paths-follow.md
  • packages/core/src/app/components/image-placeholder.tsx
  • packages/core/src/app/components/sidebar/sidebar-footer.tsx
  • packages/core/src/app/components/style-panel/use-design.ts
  • packages/core/src/app/lib/assets.ts
  • packages/core/src/app/lib/dev-api.test.ts
  • packages/core/src/app/lib/dev-api.ts
  • packages/core/src/app/lib/folders.ts
  • packages/core/src/app/lib/inspector/use-comments.ts
  • packages/core/src/app/lib/inspector/use-editor.ts
  • packages/core/src/app/lib/inspector/use-notes.ts
  • packages/core/src/app/lib/use-restart-server.ts
  • packages/core/src/app/routes/slide.tsx
  • packages/core/src/vite/design-plugin.ts
  • packages/core/src/vite/notes-plugin.ts
  • packages/core/src/vite/routes/assets.ts
  • packages/core/src/vite/routes/base-routing.test.ts
  • packages/core/src/vite/routes/comments.ts
  • packages/core/src/vite/routes/edit.ts
  • packages/core/src/vite/routes/folders.ts
  • packages/core/src/vite/routes/mount.test.ts
  • packages/core/src/vite/routes/mount.ts
  • packages/core/src/vite/routes/restart.ts
  • packages/core/src/vite/routes/slides.ts
  • packages/core/src/vite/routes/svgl.ts
  • packages/core/src/vite/routes/update.ts

@iddogino

iddogino commented Aug 5, 2026

Copy link
Copy Markdown
Author

@1weiho would you mind taking a look?

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.

[Bug]: Dev authoring APIs ignore configured base under subpath hosting

1 participant