11import { docsMetadata } from " @/lib/utils" ;
22
33export const metadata = docsMetadata ({
4- title: " Tanstack/ Start Setup" ,
5- description: " Learn how to set up a Tanstack/ Start project with UploadThing" ,
4+ title: " TanStack Start Setup" ,
5+ description: " Learn how to set up a TanStack Start project with UploadThing" ,
66 category: " Getting Started" ,
77});
88
9- # Getting Started with Tanstack/ Start
9+ # Getting Started with TanStack Start
1010
1111## Package Setup
1212
@@ -29,9 +29,9 @@ UPLOADTHING_TOKEN=... # A token for interacting with the SDK
2929</Warning >
3030
3131<Note >
32- Tanstack Start is currently in beta, this guide works at the time of writing
33- ( ` v1.95.0 ` ) but there might be some breaking changes introduced in the
34- framework that we have not kept up to date with .
32+ TanStack Start is currently in release candidate (RC). The APIs in this
33+ guide match the current v1 RC server-route conventions, but may still change
34+ before 1.0 .
3535</Note >
3636
3737## Set Up A FileRouter
@@ -52,7 +52,7 @@ of a FileRoute similar to an endpoint, it has:
5252To get full insight into what you can do with the FileRoutes, please refer to
5353the [ File Router API] ( /file-routes ) .
5454
55- ``` ts {{ title: "app /server/uploadthing.ts" }}
55+ ``` ts {{ title: "src /server/uploadthing.ts" }}
5656import { createUploadthing , UploadThingError } from " uploadthing/server" ;
5757import type { FileRouter } from " uploadthing/server" ;
5858
@@ -101,28 +101,38 @@ export type UploadRouter = typeof uploadRouter;
101101### Create an API route using the FileRouter
102102
103103<Note >
104- File path here doesn't matter, you can serve this from any route. We recommend
105- serving it from ` /api/uploadthing ` .
104+ TanStack Start server routes can live anywhere under ` src/routes ` , but this
105+ guide uses ` src/routes/api/uploadthing.ts ` so the endpoint is served from
106+ ` /api/uploadthing ` .
106107</Note >
107108
108- <Warning >
109- Make sure to configure API entry handler in ` app/api.ts ` . For more
110- information, please refer to the [ @tanstack/start
111- docs] ( https://tanstack.com/router/latest/docs/framework/react/start/api-routes#setting-up-the-entry-handler ) .
112- </Warning >
109+ <Note >
110+ TanStack Start server routes now live directly in your ` src/routes ` tree, so
111+ ` src/routes/api/uploadthing.ts ` automatically serves ` /api/uploadthing ` . For
112+ more information, please refer to the [ TanStack Start server-routes
113+ docs] ( https://tanstack.com/start/latest/docs/framework/react/guide/server-routes ) .
114+ </Note >
113115
114- ``` ts {{ title: "app /routes/api/uploadthing.ts" }}
115- import { createAPIFileRoute } from " @tanstack/start/api " ;
116+ ``` ts {{ title: "src /routes/api/uploadthing.ts" }}
117+ import { createFileRoute } from " @tanstack/react-router " ;
116118
117119import { createRouteHandler } from " uploadthing/server" ;
118120
119121import { uploadRouter } from " ../../server/uploadthing" ;
120122
121- const handlers = createRouteHandler ({ router: uploadRouter });
122-
123- export const Route = createAPIFileRoute (" /api/uploadthing" )({
124- GET: handlers ,
125- POST: handlers ,
123+ const handler = createRouteHandler ({ router: uploadRouter });
124+
125+ export const Route = createFileRoute (" /api/uploadthing" )({
126+ server: {
127+ handlers: {
128+ GET : async ({ request }) => {
129+ return handler (request );
130+ },
131+ POST : async ({ request }) => {
132+ return handler (request );
133+ },
134+ },
135+ },
126136});
127137```
128138
@@ -135,7 +145,7 @@ We provide components to make uploading easier. We highly recommend re-exporting
135145them with the types assigned, but you CAN import the components individually
136146from ` @uploadthing/react ` instead.
137147
138- ``` ts {{ title: "app /utils/uploadthing.ts" }}
148+ ``` ts {{ title: "src /utils/uploadthing.ts" }}
139149import {
140150 generateReactHelpers ,
141151 generateUploadButton ,
@@ -189,7 +199,7 @@ export const { useUploadThing } = generateReactHelpers<UploadRouter>();
189199 <Tab>
190200 Include our CSS file in the root layout to make sure the components look right!
191201
192- ```tsx {{ title : " app /routes/__root.tsx" }}
202+ ```tsx {{ title : " src /routes/__root.tsx" }}
193203 import uploadthingCss from "@uploadthing /react/styles.css?url";
194204
195205 export const Route = createRootRoute({
@@ -204,12 +214,12 @@ export const { useUploadThing } = generateReactHelpers<UploadRouter>();
204214
205215## Mount A Button And Upload!
206216
207- ``` tsx {{ title: "app /routes/index.tsx" }}
217+ ``` tsx {{ title: "src /routes/index.tsx" }}
208218import { createFileRoute } from " @tanstack/react-router" ;
209219
210220import { UploadButton } from " ../utils/uploadthing" ;
211221
212- export const APIRoute = createFileRoute (" /" )({
222+ export const Route = createFileRoute (" /" )({
213223 component: Home ,
214224});
215225
0 commit comments