Skip to content

How to have both trpc and API handler? #3399

Closed Answered by GabriFila
GabriFila asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @davidtedmanjones

I managed to expose a tRPC endpoint at /api/trpc by creating the file app/routes/api/trpc/$.ts with:

import { createAPIFileRoute } from '@tanstack/react-start/api'
import { fetchRequestHandler } from '@trpc/server/adapters/fetch'
import { initTRPC } from '@trpc/server'

const t = initTRPC.create()

const POSTS = [
  { id: '1', title: 'First post' },
  { id: '2', title: 'Second post' },
  { id: '3', title: 'Third post' },
  { id: '4', title: 'Fourth post' },
  { id: '5', title: 'Fifth post' },
  { id: '6', title: 'Sixth post' },
  { id: '7', title: 'Seventh post' },
  { id: '8', title: 'Eighth post' },
  { id: '9', title: 'Ninth post' },
  { id: '10', title: 'Tenth …

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@ram0973
Comment options

@ram0973
Comment options

Comment options

You must be logged in to vote
1 reply
@davidtedmanjones
Comment options

Answer selected by GabriFila
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants