-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Tunnel route helper + Dynamic tunnel route generator for TanStack Start React #20264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nikolovlazar
merged 24 commits into
develop
from
lazarnikolov/js-2140-tanstack-start-tunnel-adapter
Apr 23, 2026
Merged
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
ef7b5e9
Add a TanStack Start tunnel route helper
nikolovlazar 1691509
Merge branch 'develop' into lazarnikolov/js-2140-tanstack-start-tunne…
nikolovlazar 316be89
Add TanStack Start tunnel route e2e coverage
nikolovlazar e6b6290
Merge branch 'lazarnikolov/js-2140-tanstack-start-tunnel-adapter' of …
nikolovlazar 08b4154
Refactor TanStack Start e2e app to cover managed tunnel route variants
nikolovlazar 3991017
Merge branch 'develop' into lazarnikolov/js-2140-tanstack-start-tunne…
nikolovlazar 98202a9
Generate stable 8-character tunnel route paths
nikolovlazar 320a55f
refactor(tanstackstart-react): mark tunnel route cache key internal
nikolovlazar 73fbbeb
test(tanstackstart-react): narrow tunnel response matcher
nikolovlazar 5a2c6e9
Merge branch 'develop' into lazarnikolov/js-2140-tanstack-start-tunne…
nikolovlazar ee3da8d
fix(tanstackstart-react): stub createSentryTunnelRoute on client
nikolovlazar 1d827f5
Refactor TanStack Start tunnel route handling
nikolovlazar 7c9124c
Merge branch 'develop' into lazarnikolov/js-2140-tanstack-start-tunne…
nikolovlazar 4390705
Fix tunnel route lint issues
nikolovlazar e68a210
Refactor TanStack tunnel route config
nikolovlazar c993616
fix(tanstackstart-react): treat empty tunnel path as omitted
nikolovlazar 52c33cb
fix(tanstackstart-react): use path in tunnelRoute tests and type options
nikolovlazar d77dec4
Merge branch 'develop' into lazarnikolov/js-2140-tanstack-start-tunne…
nikolovlazar 29a5d89
style(tanstackstart-react): format sentryTanstackStart test imports
nikolovlazar c356b37
fix(tanstackstart-react): detect tunnel route conflicts under both ts…
nikolovlazar 9e04b81
refactor(tanstackstart-react): simplify allowedDsns options check
nikolovlazar da03651
test(tanstackstart-react): add e2e variant for object-form tunnelRoute
nikolovlazar 00c9a99
Merge branch 'develop' into lazarnikolov/js-2140-tanstack-start-tunne…
nikolovlazar af60d11
test(tanstackstart-react): drop tunnel chain from default test:assert
nikolovlazar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { handleTunnelRequest } from '@sentry/core'; | ||
|
|
||
| export interface CreateSentryTunnelRouteOptions { | ||
| allowedDsns: string[]; | ||
| } | ||
|
|
||
| type SentryTunnelRouteHandlerContext = { | ||
| request: Request; | ||
| }; | ||
|
|
||
| type SentryTunnelRoute = { | ||
| handlers: { | ||
| POST: (context: SentryTunnelRouteHandlerContext) => Promise<Response>; | ||
| }; | ||
| }; | ||
|
|
||
| /** | ||
| * Creates a TanStack Start server route configuration for tunneling Sentry envelopes. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { createFileRoute } from '@tanstack/react-router'; | ||
| * import * as Sentry from '@sentry/tanstackstart-react'; | ||
| * | ||
| * export const Route = createFileRoute('/monitoring')({ | ||
| * server: Sentry.createSentryTunnelRoute({ | ||
| * allowedDsns: ['https://public@o0.ingest.sentry.io/0'], | ||
| * }), | ||
| * }); | ||
| * ``` | ||
| */ | ||
| export function createSentryTunnelRoute(options: CreateSentryTunnelRouteOptions): SentryTunnelRoute { | ||
| return { | ||
| handlers: { | ||
| POST: async ({ request }) => { | ||
| return handleTunnelRequest({ | ||
| request, | ||
| allowedDsns: options.allowedDsns, | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
| } |
48 changes: 48 additions & 0 deletions
48
packages/tanstackstart-react/test/server/tunnelRoute.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { afterEach, describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| const handleTunnelRequestSpy = vi.fn(); | ||
|
|
||
| vi.mock('@sentry/core', async importOriginal => { | ||
| const original = await importOriginal(); | ||
| return { | ||
| ...original, | ||
| handleTunnelRequest: (...args: unknown[]) => handleTunnelRequestSpy(...args), | ||
| }; | ||
| }); | ||
|
|
||
| const { createSentryTunnelRoute } = await import('../../src/server/tunnelRoute'); | ||
|
|
||
| describe('createSentryTunnelRoute', () => { | ||
| afterEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('returns a server route config with only a POST handler', () => { | ||
| const route = createSentryTunnelRoute({ | ||
| allowedDsns: ['https://public@o0.ingest.sentry.io/0'], | ||
| }); | ||
|
|
||
| expect(Object.keys(route.handlers)).toEqual(['POST']); | ||
| expect(route.handlers.POST).toBeTypeOf('function'); | ||
| }); | ||
|
|
||
| it('forwards the request and allowed DSNs to handleTunnelRequest', async () => { | ||
| const request = new Request('http://localhost:3000/monitoring', { method: 'POST', body: 'envelope' }); | ||
| const allowedDsns = ['https://public@o0.ingest.sentry.io/0']; | ||
| const response = new Response('ok', { status: 200 }); | ||
|
|
||
| handleTunnelRequestSpy.mockResolvedValueOnce(response); | ||
|
|
||
| const route = createSentryTunnelRoute({ allowedDsns }); | ||
| const result = await route.handlers.POST({ request }); | ||
|
|
||
| expect(handleTunnelRequestSpy).toHaveBeenCalledTimes(1); | ||
| const [options] = handleTunnelRequestSpy.mock.calls[0]!; | ||
| expect(options).toEqual({ | ||
| request, | ||
| allowedDsns, | ||
| }); | ||
| expect(options.allowedDsns).toBe(allowedDsns); | ||
| expect(result).toBe(response); | ||
| }); | ||
| }); | ||
|
cursor[bot] marked this conversation as resolved.
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.