diff --git a/package.json b/package.json index 1da4312..a3bc795 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,6 @@ "type": "module", "version": "0.3.5", "license": "MIT", - "main": "./dist/module.cjs", - "types": "./dist/types.d.ts", "exports": { "./package.json": "./package.json", ".": { @@ -16,6 +14,8 @@ "import": "./dist/runtime/api.mjs" } }, + "main": "./dist/module.cjs", + "types": "./dist/types.d.ts", "files": [ "dist", "*.d.ts" @@ -42,6 +42,7 @@ "dedent": "^0.7.0", "defu": "^6.1.1", "h3": "^1.0.2", + "ofetch": "^1.0.0", "ohash": "^1.0.0", "pathe": "^1.0.0", "ufo": "^1.0.1" diff --git a/playground/pages/index.vue b/playground/pages/index.vue index 18a8ffa..fac09cc 100644 --- a/playground/pages/index.vue +++ b/playground/pages/index.vue @@ -1,5 +1,5 @@ diff --git a/playground/server/trpc/index.ts b/playground/server/trpc/index.ts index fab7a96..bf4e659 100644 --- a/playground/server/trpc/index.ts +++ b/playground/server/trpc/index.ts @@ -29,7 +29,6 @@ export const router = trpc.router() .mutation('addTodo', { input: TodoShape, async resolve(req) { - console.log(req.input) return await $fetch(`${baseURL}/todos`, { method: 'POST', body: req.input, @@ -43,7 +42,7 @@ export async function createContext(event: H3Event) { // This is just an example of something you'd might want to do in your ctx fn // const x = useCookies(event) - console.log(event.req.headers) + console.log(event.node.req.headers) return { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 95a65d4..1fd6c09 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,6 +16,7 @@ importers: eslint: ^8.25.0 h3: ^1.0.2 nuxt: 3.0.0 + ofetch: ^1.0.0 ohash: ^1.0.0 pathe: ^1.0.0 ufo: ^1.0.1 @@ -27,6 +28,7 @@ importers: dedent: 0.7.0 defu: 6.1.1 h3: 1.0.2 + ofetch: 1.0.0 ohash: 1.0.0 pathe: 1.0.0 ufo: 1.0.1 @@ -4505,7 +4507,6 @@ packages: destr: 1.2.2 node-fetch-native: 1.0.1 ufo: 1.0.1 - dev: true /ohash/1.0.0: resolution: {integrity: sha512-kxSyzq6tt+6EE/xCnD1XaFhCCjUNUaz3X30rJp6mnjGLXAAvuPFqohMdv0aScWzajR45C29HyBaXZ8jXBwnh9A==} diff --git a/src/module.ts b/src/module.ts index af877ac..0d8f1e1 100644 --- a/src/module.ts +++ b/src/module.ts @@ -26,12 +26,12 @@ export default defineNuxtModule({ async setup(options, nuxt) { const logger = useLogger(metaName) - const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url)) - nuxt.options.build.transpile.push(runtimeDir) - const handlerPath = join(nuxt.options.buildDir, 'trpc-handler.ts') const trpcOptionsPath = join(nuxt.options.srcDir, 'server/trpc') + const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url)) + nuxt.options.build.transpile.push(runtimeDir, handlerPath) + // Final resolved configuration const finalConfig = nuxt.options.runtimeConfig.public.trpc = defu(nuxt.options.runtimeConfig.public.trpc, { baseURL: options.baseURL, @@ -77,4 +77,3 @@ export default defineNuxtModule({ } }, }) - diff --git a/src/runtime/plugin.ts b/src/runtime/plugin.ts index 3b0c906..dfcf9b5 100644 --- a/src/runtime/plugin.ts +++ b/src/runtime/plugin.ts @@ -1,6 +1,6 @@ import * as trpc from '@trpc/client' import { unref } from 'vue' -import { FetchError } from 'ohmyfetch' +import { FetchError } from 'ofetch' import { useClientHeaders } from './client' import { defineNuxtPlugin, useRequestHeaders, useRuntimeConfig } from '#imports' import type { router } from '~/server/trpc'