Initial commit, most things work
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				Build and deploy / deploy (push) Failing after 46s
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	Build and deploy / deploy (push) Failing after 46s
				
			This commit is contained in:
		
							
								
								
									
										34
									
								
								src/app/api/trpc/[trpc]/route.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/app/api/trpc/[trpc]/route.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| import { fetchRequestHandler } from "@trpc/server/adapters/fetch"; | ||||
| import type { NextRequest } from "next/server"; | ||||
|  | ||||
| import { env } from "@/env"; | ||||
| import { appRouter } from "@/server/api/root"; | ||||
| import { createTRPCContext } from "@/server/api/trpc"; | ||||
|  | ||||
| /** | ||||
|  * This wraps the `createTRPCContext` helper and provides the required context for the tRPC API when | ||||
|  * handling a HTTP request (e.g. when you make requests from Client Components). | ||||
|  */ | ||||
| const createContext = async (req: NextRequest) => { | ||||
| 	return createTRPCContext({ | ||||
| 		headers: req.headers, | ||||
| 	}); | ||||
| }; | ||||
|  | ||||
| const handler = (req: NextRequest) => | ||||
| 	fetchRequestHandler({ | ||||
| 		endpoint: "/api/trpc", | ||||
| 		req, | ||||
| 		router: appRouter, | ||||
| 		createContext: () => createContext(req), | ||||
| 		onError: | ||||
| 			env.NODE_ENV === "development" | ||||
| 				? ({ path, error }) => { | ||||
| 						console.error( | ||||
| 							`❌ tRPC failed on ${path ?? "<no-path>"}: ${error.message}`, | ||||
| 						); | ||||
| 					} | ||||
| 				: undefined, | ||||
| 	}); | ||||
|  | ||||
| export { handler as GET, handler as POST }; | ||||
		Reference in New Issue
	
	Block a user