mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-14 20:19:33 +01:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fca82a027e | ||
|
|
7995e892db |
@@ -1,10 +1,8 @@
|
||||
{
|
||||
"name": "trpc-nuxt",
|
||||
"type": "module",
|
||||
"version": "0.3.5",
|
||||
"version": "0.3.6",
|
||||
"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"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { useClient, useClientHeaders, useAsyncQuery } from '#imports'
|
||||
import { useAsyncQuery, useClient, useClientHeaders } from '#imports'
|
||||
const client = useClient()
|
||||
const headers = useClientHeaders()
|
||||
const { data: todos, pending, error, refresh } = await useAsyncQuery(['getTodos'])
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { useRoute, useAsyncQuery } from '#imports'
|
||||
import { useAsyncQuery, useRoute } from '#imports'
|
||||
const route = useRoute()
|
||||
const { data: todo, pending, error } = await useAsyncQuery(['getTodo', Number(route.params.id)])
|
||||
</script>
|
||||
|
||||
@@ -29,7 +29,6 @@ export const router = trpc.router<Context>()
|
||||
.mutation('addTodo', {
|
||||
input: TodoShape,
|
||||
async resolve(req) {
|
||||
console.log(req.input)
|
||||
return await $fetch<Todo>(`${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 {
|
||||
|
||||
|
||||
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@@ -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==}
|
||||
|
||||
@@ -26,12 +26,12 @@ export default defineNuxtModule<ModuleOptions>({
|
||||
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<ModuleOptions>({
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user