Skip to content

fix(tanstack-start): support custom API routes - #18590

Open
r1tsuu wants to merge 3 commits into
mainfrom
fix-tanstack-custom-api-route
Open

r1tsuu wants to merge 3 commits into
mainfrom
fix-tanstack-custom-api-route

Conversation

@r1tsuu

@r1tsuu r1tsuu commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Description

Fixes TanStack Start REST requests returning 404 when routes.api is customized.

The TanStack handler now passes the request pathname directly to Payload instead of rebuilding it with a hard-coded /api prefix. In Next.js, the endpoint path is constructed using config.routes.api.

Testing

  • Set routes.api to /custom-api in the endpoints test suite config, so its existing int tests run under a custom API route.
  • Added test/endpoints/tanstack.int.spec.ts, which calls the TanStack handleAPIRoute handler with a request under the custom API route and verifies it resolves (fails with 404 without the fix).

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

📦 esbuild Bundle Analysis for payload

This analysis was generated by esbuild-bundle-analyzer. 🤖
This PR introduced no changes to the esbuild bundle! 🙌

@r1tsuu
r1tsuu requested a review from jacobsfletch October 8, 2026 13:16
...config,
routes: {
...config.routes,
api: '/custom-api',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't this just be written directly into the Payload config? Let's also move this custom route setup to the test dir. The root app dirs here are meant to be unmodified sources of truth.

Comment thread test/collections-rest/config.ts Outdated
],
endpoints: [
{
handler: ({ payload }) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a very strange way to test this. Let's reuse the existing endpoints suite instead, and define the routes.api directly on the Payload config (this will affect all api routes in this suite but that's fine). It will need its own app and app-tanstack dirs to define the custom api path. This will isolate the change to this one suite.

@r1tsuu
r1tsuu marked this pull request as draft October 9, 2026 12:59
@r1tsuu
r1tsuu marked this pull request as ready for review October 9, 2026 13:05

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants