mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-25 01:10:37 +01:00
refactor!: replace trpcURL option with endpoint
This commit is contained in:
@@ -57,6 +57,9 @@
|
|||||||
"zod": "^3.16.0"
|
"zod": "^3.16.0"
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"extends": "@antfu"
|
"extends": "@antfu",
|
||||||
|
"rules": {
|
||||||
|
"no-console": "warn"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { addAutoImport, addPlugin, addServerHandler, addTemplate, defineNuxtModu
|
|||||||
|
|
||||||
export interface ModuleOptions {
|
export interface ModuleOptions {
|
||||||
baseURL: string
|
baseURL: string
|
||||||
trpcURL: string
|
endpoint: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defineNuxtModule<ModuleOptions>({
|
export default defineNuxtModule<ModuleOptions>({
|
||||||
@@ -18,7 +18,7 @@ export default defineNuxtModule<ModuleOptions>({
|
|||||||
},
|
},
|
||||||
defaults: {
|
defaults: {
|
||||||
baseURL: 'http://localhost:3000',
|
baseURL: 'http://localhost:3000',
|
||||||
trpcURL: '/api/trpc',
|
endpoint: '/trpc',
|
||||||
},
|
},
|
||||||
async setup(options, nuxt) {
|
async setup(options, nuxt) {
|
||||||
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
|
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
|
||||||
@@ -33,7 +33,7 @@ export default defineNuxtModule<ModuleOptions>({
|
|||||||
// Final resolved configuration
|
// Final resolved configuration
|
||||||
const finalConfig = nuxt.options.runtimeConfig.public.trpc = defu(nuxt.options.runtimeConfig.public.trpc, {
|
const finalConfig = nuxt.options.runtimeConfig.public.trpc = defu(nuxt.options.runtimeConfig.public.trpc, {
|
||||||
baseURL: options.baseURL,
|
baseURL: options.baseURL,
|
||||||
trpcURL: options.trpcURL,
|
endpoint: options.endpoint,
|
||||||
})
|
})
|
||||||
|
|
||||||
addAutoImport([
|
addAutoImport([
|
||||||
@@ -43,7 +43,7 @@ export default defineNuxtModule<ModuleOptions>({
|
|||||||
])
|
])
|
||||||
|
|
||||||
addServerHandler({
|
addServerHandler({
|
||||||
route: `${finalConfig.trpcURL}/*`,
|
route: `${finalConfig.endpoint}/*`,
|
||||||
handler: handlerPath,
|
handler: handlerPath,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ export default defineNuxtModule<ModuleOptions>({
|
|||||||
|
|
||||||
export default createTRPCHandler({
|
export default createTRPCHandler({
|
||||||
...functions,
|
...functions,
|
||||||
endpoint: '${finalConfig.trpcURL}'
|
endpoint: '${finalConfig.endpoint}'
|
||||||
})
|
})
|
||||||
`
|
`
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|||||||
const headers = useRequestHeaders()
|
const headers = useRequestHeaders()
|
||||||
const otherHeaders = useClientHeaders()
|
const otherHeaders = useClientHeaders()
|
||||||
const client = trpc.createTRPCClient<AppRouter>({
|
const client = trpc.createTRPCClient<AppRouter>({
|
||||||
url: `${config.baseURL}${config.trpcURL}`,
|
url: `${config.baseURL}${config.endpoint}`,
|
||||||
headers: () => {
|
headers: () => {
|
||||||
return {
|
return {
|
||||||
...unref(otherHeaders),
|
...unref(otherHeaders),
|
||||||
|
|||||||
Reference in New Issue
Block a user