Compare commits

...

15 Commits

Author SHA1 Message Date
Robert Soriano
75980c0953 release v0.3.0 2022-09-24 08:25:33 -07:00
Robert Soriano
a6f61d404f feat(deps): bump h3 to 0.7.21 2022-09-24 08:24:57 -07:00
Robert Soriano
e53d1be61e feat(deps): bump @nuxt/kit to 3.0.0-rc-11 2022-09-24 08:23:29 -07:00
Robert Soriano
d152ebc7be chore: remove volta config 2022-09-24 08:20:24 -07:00
Robert Soriano
f6daa2b7c3 Merge pull request #28 from robinWongM/feature/direct-api-call-during-ssr
feat: use globalThis.$fetch to call API handler directly on server-side
2022-09-24 08:19:16 -07:00
Robin Wong
7962c7f61e fix: return original FetchResponse when ohmyfetch throws error 2022-09-18 09:46:59 +00:00
Robin Wong
453845fb14 fix: eslint errors 2022-09-18 08:44:43 +00:00
Robin Wong
ee3ee485ba feat: use globalThis.$fetch to call API handler directly on server-side 2022-09-16 16:53:15 +00:00
Robert Soriano
cdf29bee67 release v0.2.8 2022-09-08 09:36:32 -07:00
Robert Soriano
d3d35404b1 update release script 2022-09-08 09:36:24 -07:00
Robert Soriano
e57c919157 Merge pull request #26 from elfpie/feature/update-nuxt
Bump nuxt to RC9
2022-09-08 08:11:24 -07:00
Felipe
d0fffbbc64 feat(deps): bump nuxt to 3.0.0-rc.9 2022-09-07 17:59:23 -03:00
Felipe
433d5ada46 feat(deps): bump @trpc/client to 9.27.2 2022-09-07 17:59:23 -03:00
Felipe
5d180460af feat(deps): bump @trpc/server to 9.27.2 2022-09-07 17:59:23 -03:00
Felipe
8991148d39 feat(deps): bump @nuxt/kit to 3.0.0-rc.9 2022-09-07 17:59:15 -03:00
5 changed files with 791 additions and 780 deletions

View File

@@ -1,7 +1,7 @@
{ {
"name": "trpc-nuxt", "name": "trpc-nuxt",
"type": "module", "type": "module",
"version": "0.2.7", "version": "0.3.0",
"packageManager": "pnpm@7.5.0", "packageManager": "pnpm@7.5.0",
"license": "MIT", "license": "MIT",
"main": "./dist/module.cjs", "main": "./dist/module.cjs",
@@ -28,16 +28,16 @@
"build:playground": "nuxi build playground", "build:playground": "nuxi build playground",
"lint": "eslint .", "lint": "eslint .",
"lint:fix": "eslint . --fix", "lint:fix": "eslint . --fix",
"release": "bumpp --commit --push --tag && pnpm publish", "release": "bumpp --commit --push --tag && npm publish",
"prepare": "nuxi prepare playground" "prepare": "nuxi prepare playground"
}, },
"dependencies": { "dependencies": {
"@nuxt/kit": "3.0.0-rc.8", "@nuxt/kit": "3.0.0-rc.11",
"@trpc/client": "^9.27.1", "@trpc/client": "^9.27.2",
"@trpc/server": "^9.27.1", "@trpc/server": "^9.27.2",
"dedent": "^0.7.0", "dedent": "^0.7.0",
"defu": "^6.0.0", "defu": "^6.0.0",
"h3": "^0.7.10", "h3": "^0.7.21",
"ohash": "^0.1.5", "ohash": "^0.1.5",
"pathe": "^0.3.0", "pathe": "^0.3.0",
"ufo": "^0.8.5" "ufo": "^0.8.5"
@@ -49,7 +49,7 @@
"@types/dedent": "^0.7.0", "@types/dedent": "^0.7.0",
"bumpp": "^7.2.0", "bumpp": "^7.2.0",
"eslint": "^8.14.0", "eslint": "^8.14.0",
"nuxt": "3.0.0-rc.8", "nuxt": "3.0.0-rc.11",
"pnpm": "^7.5.0", "pnpm": "^7.5.0",
"trpc-nuxt": "workspace:*", "trpc-nuxt": "workspace:*",
"zod": "^3.16.0" "zod": "^3.16.0"
@@ -59,8 +59,5 @@
"rules": { "rules": {
"no-console": "warn" "no-console": "warn"
} }
},
"volta": {
"node": "16.14.2"
} }
} }

View File

@@ -5,7 +5,7 @@ import Module from '../src/module'
export default defineNuxtConfig({ export default defineNuxtConfig({
modules: [Module], modules: [Module],
runtimeConfig: { runtimeConfig: {
baseURL: 'http://localhost:3000', baseURL: '',
}, },
typescript: { typescript: {
strict: true, strict: true,

1529
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,7 @@ import { join, resolve } from 'pathe'
import { defu } from 'defu' import { defu } from 'defu'
import dedent from 'dedent' import dedent from 'dedent'
import { addAutoImport, addPlugin, addServerHandler, addTemplate, defineNuxtModule } from '@nuxt/kit' import { addImports, addPlugin, addServerHandler, addTemplate, defineNuxtModule } from '@nuxt/kit'
export interface ModuleOptions { export interface ModuleOptions {
baseURL: string baseURL: string
@@ -16,7 +16,7 @@ export default defineNuxtModule<ModuleOptions>({
configKey: 'trpc', configKey: 'trpc',
}, },
defaults: { defaults: {
baseURL: 'http://localhost:3000', baseURL: '',
endpoint: '/trpc', endpoint: '/trpc',
}, },
async setup(options, nuxt) { async setup(options, nuxt) {
@@ -32,7 +32,7 @@ export default defineNuxtModule<ModuleOptions>({
endpoint: options.endpoint, endpoint: options.endpoint,
}) })
addAutoImport([ addImports([
{ name: 'useClient', from: join(runtimeDir, 'client') }, { name: 'useClient', from: join(runtimeDir, 'client') },
{ name: 'useAsyncQuery', from: join(runtimeDir, 'client') }, { name: 'useAsyncQuery', from: join(runtimeDir, 'client') },
{ name: 'useClientHeaders', from: join(runtimeDir, 'client') }, { name: 'useClientHeaders', from: join(runtimeDir, 'client') },

View File

@@ -1,5 +1,6 @@
import * as trpc from '@trpc/client' import * as trpc from '@trpc/client'
import { unref } from 'vue' import { unref } from 'vue'
import { FetchError } from 'ohmyfetch'
import { useClientHeaders } from './client' import { useClientHeaders } from './client'
import { defineNuxtPlugin, useRequestHeaders, useRuntimeConfig } from '#app' import { defineNuxtPlugin, useRequestHeaders, useRuntimeConfig } from '#app'
import type { router } from '~/server/trpc' import type { router } from '~/server/trpc'
@@ -10,14 +11,28 @@ export default defineNuxtPlugin((nuxtApp) => {
const config = useRuntimeConfig().public.trpc const config = useRuntimeConfig().public.trpc
const headers = useRequestHeaders() const headers = useRequestHeaders()
const otherHeaders = useClientHeaders() const otherHeaders = useClientHeaders()
const baseURL = process.server ? '' : config.baseURL
const client = trpc.createTRPCClient<AppRouter>({ const client = trpc.createTRPCClient<AppRouter>({
url: `${config.baseURL}${config.endpoint}`, url: `${baseURL}${config.endpoint}`,
headers: () => { headers: () => {
return { return {
...unref(otherHeaders), ...unref(otherHeaders),
...headers, ...headers,
} }
}, },
fetch: (input, options) =>
globalThis.$fetch.raw(input.toString(), options)
.catch((e) => {
if (e instanceof FetchError && e.response)
return e.response
throw e
})
.then(response => ({
...response,
json: () => Promise.resolve(response._data),
})),
}) })
nuxtApp.provide('client', client) nuxtApp.provide('client', client)