use trpc url options in api

This commit is contained in:
Robert Soriano
2022-05-19 09:25:14 -07:00
parent 38fb3edf22
commit 5b94433b8f
5 changed files with 24 additions and 7 deletions

View File

@@ -42,14 +42,14 @@ export function createTRPCHandler<Router extends AnyRouter>({
createContext,
responseMeta,
onError,
trpcURL,
}: {
router: Router
createContext?: CreateContextFn<Router>
responseMeta?: ResponseMetaFn<Router>
onError?: OnErrorFn<Router>
trpcURL: string
}) {
const url = '/api/trpc'
return defineEventHandler(async (event) => {
const {
req,
@@ -68,7 +68,7 @@ export function createTRPCHandler<Router extends AnyRouter>({
body: isMethod(event, 'GET') ? null : await useBody(event),
query: $url.searchParams,
},
path: $url.pathname.substring(url.length + 1),
path: $url.pathname.substring(trpcURL.length + 1),
createContext: async () => createContext?.(event),
responseMeta,
onError: (o) => {