refactor trpc routers
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { createTRPCNuxtClient, httpBatchLink } from "trpc-nuxt/client";
|
import { createTRPCNuxtClient, httpBatchLink } from "trpc-nuxt/client";
|
||||||
import type { AppRouter } from "~/server/api/trpc/[trpc]";
|
import type { AppRouter } from "~/server/trpc/routers/app.router";
|
||||||
import superjson from "superjson";
|
import superjson from "superjson";
|
||||||
|
|
||||||
export default defineNuxtPlugin(() => {
|
export default defineNuxtPlugin(() => {
|
||||||
|
|||||||
@@ -2,27 +2,15 @@
|
|||||||
* This is the API-handler of your app that contains all your API routes.
|
* This is the API-handler of your app that contains all your API routes.
|
||||||
* On a bigger app, you will probably want to split this file up into multiple files.
|
* On a bigger app, you will probably want to split this file up into multiple files.
|
||||||
*/
|
*/
|
||||||
import { createNuxtApiHandler } from 'trpc-nuxt'
|
import { createNuxtApiHandler } from "trpc-nuxt";
|
||||||
|
import { createContext } from "~~/server/trpc/context";
|
||||||
import { router } from '~/server/trpc/trpc'
|
import { appRouter } from "~~/server/trpc/routers/app.router";
|
||||||
import { createContext } from '~~/server/trpc/context';
|
|
||||||
import { notesRouter } from '~~/server/trpc/routers/notes.router';
|
|
||||||
import { authRouter } from '~~/server/trpc/routers/auth.router';
|
|
||||||
import { accountRouter } from '~~/server/trpc/routers/account.router';
|
|
||||||
|
|
||||||
export const appRouter = router({
|
|
||||||
notes: notesRouter,
|
|
||||||
auth: authRouter,
|
|
||||||
account: accountRouter,
|
|
||||||
})
|
|
||||||
|
|
||||||
// export only the type definition of the API
|
|
||||||
// None of the actual implementation is exposed to the client
|
|
||||||
export type AppRouter = typeof appRouter;
|
|
||||||
|
|
||||||
// export API handler
|
// export API handler
|
||||||
export default createNuxtApiHandler({
|
export default createNuxtApiHandler({
|
||||||
router: appRouter,
|
router: appRouter,
|
||||||
createContext: createContext,
|
createContext: createContext,
|
||||||
onError({ error}) { console.error(error)},
|
onError({ error }) {
|
||||||
})
|
console.error(error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|||||||
14
server/trpc/routers/app.router.ts
Normal file
14
server/trpc/routers/app.router.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { router } from "~/server/trpc/trpc";
|
||||||
|
import { notesRouter } from "./notes.router";
|
||||||
|
import { authRouter } from "./auth.router";
|
||||||
|
import { accountRouter } from "./account.router";
|
||||||
|
|
||||||
|
export const appRouter = router({
|
||||||
|
notes: notesRouter,
|
||||||
|
auth: authRouter,
|
||||||
|
account: accountRouter,
|
||||||
|
});
|
||||||
|
|
||||||
|
// export only the type definition of the API
|
||||||
|
// None of the actual implementation is exposed to the client
|
||||||
|
export type AppRouter = typeof appRouter;
|
||||||
Reference in New Issue
Block a user