mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-27 02:10:35 +01:00
fix: headers missing
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { fileURLToPath } from 'url'
|
||||
import { join } from 'pathe'
|
||||
import { join, resolve } from 'pathe'
|
||||
import { defu } from 'defu'
|
||||
|
||||
import { addServerHandler, addTemplate, defineNuxtModule } from '@nuxt/kit'
|
||||
import { addPluginTemplate, addServerHandler, addTemplate, defineNuxtModule } from '@nuxt/kit'
|
||||
|
||||
export interface ModuleOptions {
|
||||
baseURL: string
|
||||
@@ -48,18 +48,22 @@ export default defineNuxtModule<ModuleOptions>({
|
||||
write: true,
|
||||
getContents() {
|
||||
return `
|
||||
import * as trpc from '@trpc/client'
|
||||
import type { router } from '${trpcOptionsPath}'
|
||||
|
||||
const client = trpc.createTRPCClient<typeof router>({
|
||||
url: '${finalConfig.baseURL}${finalConfig.trpcURL}',
|
||||
})
|
||||
|
||||
export const useClient = () => client
|
||||
export const useClient = () => {
|
||||
const { $client } = useNuxtApp()
|
||||
return $client
|
||||
}
|
||||
`
|
||||
},
|
||||
})
|
||||
|
||||
addPluginTemplate({
|
||||
src: resolve(runtimeDir, 'plugin.ts'),
|
||||
write: true,
|
||||
options: {
|
||||
url: `${finalConfig.baseURL}${finalConfig.trpcURL}`,
|
||||
},
|
||||
})
|
||||
|
||||
addTemplate({
|
||||
filename: 'trpc-handler.ts',
|
||||
write: true,
|
||||
|
||||
Reference in New Issue
Block a user