-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #206 from axiomhq/trpc-example-2
docs: update tRPC / app router example
- Loading branch information
Showing
17 changed files
with
138 additions
and
194 deletions.
There are no files selected for viewing
This file contains 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 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,9 @@ | ||
/** @type {import("prettier").Config} */ | ||
const config = { | ||
trailingComma: 'all', | ||
tabWidth: 2, | ||
semi: true, | ||
singleQuote: true, | ||
}; | ||
|
||
export default config; |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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
22 changes: 12 additions & 10 deletions
22
examples/trpc-app-router/src/app/api/trpc/[trpc]/route.ts
This file contains 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 |
---|---|---|
@@ -1,26 +1,28 @@ | ||
import { fetchRequestHandler } from "@trpc/server/adapters/fetch"; | ||
import { withAxiomRouteHandler } from "next-axiom"; | ||
import { type NextRequest } from "next/server"; | ||
import { fetchRequestHandler } from '@trpc/server/adapters/fetch'; | ||
import { withAxiomRouteHandler } from 'next-axiom'; | ||
import { type NextRequest } from 'next/server'; | ||
|
||
import { env } from "~/env.mjs"; | ||
import { appRouter } from "~/server/api/root"; | ||
import { createTRPCContext } from "~/server/api/trpc"; | ||
import { appRouter } from '~/server/api/root'; | ||
import { createTRPCContext } from '~/server/api/trpc'; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
export const revalidate = 0; | ||
|
||
const handler = withAxiomRouteHandler((req: NextRequest) => | ||
fetchRequestHandler({ | ||
endpoint: "/api/trpc", | ||
endpoint: '/api/trpc', | ||
req, | ||
router: appRouter, | ||
createContext: () => createTRPCContext({ req }), | ||
onError: | ||
env.NODE_ENV === "development" | ||
process.env.NODE_ENV === 'development' | ||
? ({ path, error }) => { | ||
console.error( | ||
`❌ tRPC failed on ${path ?? "<no-path>"}: ${error.message}` | ||
`❌ tRPC failed on ${path ?? '<no-path>'}: ${error.message}`, | ||
); | ||
} | ||
: undefined, | ||
}) | ||
}), | ||
); | ||
|
||
export { handler as GET, handler as POST }; |
This file contains 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 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 was deleted.
Oops, something went wrong.
This file contains 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 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
Oops, something went wrong.