mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-14 20:19:33 +01:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 25e09b2e30 | |||
| 0612716187 | |||
|
|
55712e3027 | ||
|
|
0fec55a3ae | ||
|
|
8f9e398ae2 | ||
|
|
092e3495fd | ||
|
|
230422bb16 | ||
|
|
057c8f8d3a | ||
|
|
9808375f31 | ||
|
|
8e893a2e30 | ||
|
|
f74273190f | ||
|
|
283400d41a | ||
|
|
5221dc0515 |
42
CHANGELOG.md
42
CHANGELOG.md
@@ -1,6 +1,48 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
|
||||||
|
## v0.10.12
|
||||||
|
|
||||||
|
[compare changes](https://github.com/wobsoriano/trpc-nuxt/compare/v0.10.11...v0.10.12)
|
||||||
|
|
||||||
|
### 🩹 Fixes
|
||||||
|
|
||||||
|
- Expect ofetch missing error response type ([8f9e398](https://github.com/wobsoriano/trpc-nuxt/commit/8f9e398))
|
||||||
|
|
||||||
|
### 💅 Refactors
|
||||||
|
|
||||||
|
- Explicitly copy headers to custom fetcher ([0fec55a](https://github.com/wobsoriano/trpc-nuxt/commit/0fec55a))
|
||||||
|
|
||||||
|
### 📖 Documentation
|
||||||
|
|
||||||
|
- Add response caching page ([9808375](https://github.com/wobsoriano/trpc-nuxt/commit/9808375))
|
||||||
|
- Fix missing title ([057c8f8](https://github.com/wobsoriano/trpc-nuxt/commit/057c8f8))
|
||||||
|
- Fix incorrect syntax ([230422b](https://github.com/wobsoriano/trpc-nuxt/commit/230422b))
|
||||||
|
|
||||||
|
### 📦 Build
|
||||||
|
|
||||||
|
- **deps:** Bump ofetch to 1.3.2 ([092e349](https://github.com/wobsoriano/trpc-nuxt/commit/092e349))
|
||||||
|
|
||||||
|
### ❤️ Contributors
|
||||||
|
|
||||||
|
- Wobsoriano ([@wobsoriano](http://github.com/wobsoriano))
|
||||||
|
|
||||||
|
## v0.10.11
|
||||||
|
|
||||||
|
[compare changes](https://github.com/wobsoriano/trpc-nuxt/compare/v0.10.10...v0.10.11)
|
||||||
|
|
||||||
|
### 🩹 Fixes
|
||||||
|
|
||||||
|
- Add missing useLazyQuery type ([299ae55](https://github.com/wobsoriano/trpc-nuxt/commit/299ae55))
|
||||||
|
|
||||||
|
### 📖 Documentation
|
||||||
|
|
||||||
|
- Bump @nuxt-themes/docus to 1.14.6 ([f7eeb10](https://github.com/wobsoriano/trpc-nuxt/commit/f7eeb10))
|
||||||
|
|
||||||
|
### ❤️ Contributors
|
||||||
|
|
||||||
|
- Wobsoriano ([@wobsoriano](http://github.com/wobsoriano))
|
||||||
|
|
||||||
## v0.10.10
|
## v0.10.10
|
||||||
|
|
||||||
[compare changes](https://github.com/wobsoriano/trpc-nuxt/compare/v0.10.9...v0.10.10)
|
[compare changes](https://github.com/wobsoriano/trpc-nuxt/compare/v0.10.9...v0.10.10)
|
||||||
|
|||||||
51
docs/content/1.get-started/5.tips/6.response-caching.md
Normal file
51
docs/content/1.get-started/5.tips/6.response-caching.md
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
---
|
||||||
|
title: Response Caching
|
||||||
|
---
|
||||||
|
|
||||||
|
## Response Caching
|
||||||
|
|
||||||
|
Your server responses must [satisfy some criteria](https://vercel.com/docs/concepts/functions/serverless-functions/edge-caching) in order for them to be cached (i.e. by Vercel's Edge Network). Please refer to [this section of the tRPC.io documentation](https://trpc.io/docs/caching) for more information.
|
||||||
|
|
||||||
|
The `createNuxtApiHandler` function conveniently allows you to specify a `responseMeta` function.
|
||||||
|
|
||||||
|
```ts [server/api/trpc/[trpc].ts]
|
||||||
|
import { createNuxtApiHandler } from 'trpc-nuxt'
|
||||||
|
import { appRouter } from '~/server/trpc/routers'
|
||||||
|
|
||||||
|
export default createNuxtApiHandler({
|
||||||
|
router: appRouter,
|
||||||
|
/**
|
||||||
|
* @link https://trpc.io/docs/caching#api-response-caching
|
||||||
|
*/
|
||||||
|
responseMeta(opts) {
|
||||||
|
// cache request for 1 day + revalidate once every second
|
||||||
|
const ONE_DAY_IN_SECONDS = 60 * 60 * 24;
|
||||||
|
|
||||||
|
return {
|
||||||
|
headers: {
|
||||||
|
'cache-control': `s-maxage=1, stale-while-revalidate=${ONE_DAY_IN_SECONDS}`,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also take advantage of Nitro's [Cache API](https://nitro.unjs.io/guide/cache#cache-api) if doing server-side calls:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { appRouter } from '@/server/trpc/routers'
|
||||||
|
|
||||||
|
const caller = appRouter.createCaller({})
|
||||||
|
|
||||||
|
export default cachedEventHandler(async (event) => {
|
||||||
|
const { name } = getQuery(event)
|
||||||
|
|
||||||
|
const greeting = await caller.greeting({ name })
|
||||||
|
|
||||||
|
return {
|
||||||
|
greeting
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
swr: true, maxAge: 10
|
||||||
|
})
|
||||||
|
```
|
||||||
@@ -2,21 +2,21 @@
|
|||||||
"name": "nuxt-app",
|
"name": "nuxt-app",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "nuxt build",
|
"build": "nuxi build",
|
||||||
"dev": "nuxt dev",
|
"dev": "nuxi dev",
|
||||||
"generate": "nuxt generate",
|
"generate": "nuxi generate",
|
||||||
"preview": "nuxt preview",
|
"preview": "nuxi preview",
|
||||||
"postinstall": "nuxt prepare"
|
"postinstall": "nuxi prepare"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nuxt/devtools": "latest",
|
"@nuxt/devtools": "latest",
|
||||||
"@types/node": "^20.4.2",
|
"@types/node": "20.5.7",
|
||||||
"nuxt": "^3.6.5"
|
"nuxt": "^3.7.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@trpc/client": "^10.35.0",
|
"@trpc/client": "^10.38.1",
|
||||||
"@trpc/server": "^10.35.0",
|
"@trpc/server": "^10.38.1",
|
||||||
"trpc-nuxt": "workspace:*",
|
"trpc-nuxt": "workspace:*",
|
||||||
"zod": "^3.21.4"
|
"zod": "^3.22.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
32
package.json
32
package.json
@@ -3,7 +3,7 @@
|
|||||||
"description": "End-to-end typesafe APIs in Nuxt applications.",
|
"description": "End-to-end typesafe APIs in Nuxt applications.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"packageManager": "pnpm@8.6.9",
|
"packageManager": "pnpm@8.6.9",
|
||||||
"version": "0.10.10",
|
"version": "0.10.12",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"exports": {
|
"exports": {
|
||||||
@@ -35,23 +35,23 @@
|
|||||||
"update-deps": "taze -w && pnpm i"
|
"update-deps": "taze -w && pnpm i"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@trpc/client": "^10.26.0",
|
"@trpc/client": "^10.38.1",
|
||||||
"@trpc/server": "^10.26.0"
|
"@trpc/server": "^10.38.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"h3": "^1.8.0",
|
"h3": "^1.8.1",
|
||||||
"ofetch": "^1.1.1",
|
"ofetch": "^1.3.3",
|
||||||
"ohash": "^1.1.2"
|
"ohash": "^1.1.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nuxt/eslint-config": "^0.1.1",
|
"@nuxt/eslint-config": "^0.2.0",
|
||||||
"@trpc/client": "^10.37.1",
|
"@trpc/client": "^10.38.1",
|
||||||
"@trpc/server": "^10.37.1",
|
"@trpc/server": "^10.38.1",
|
||||||
"changelogen": "^0.5.4",
|
"changelogen": "^0.5.5",
|
||||||
"eslint": "^8.45.0",
|
"eslint": "^8.48.0",
|
||||||
"taze": "^0.11.2",
|
"taze": "^0.11.2",
|
||||||
"tsup": "7.2.0",
|
"tsup": "7.2.0",
|
||||||
"typescript": "^5.1.6"
|
"typescript": "^5.2.2"
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"extends": [
|
"extends": [
|
||||||
@@ -74,9 +74,9 @@
|
|||||||
],
|
],
|
||||||
"pnpm": {
|
"pnpm": {
|
||||||
"overrides": {
|
"overrides": {
|
||||||
"nuxt": "3.6.5",
|
"nuxt": "3.7.0",
|
||||||
"@trpc/client": "10.37.1",
|
"@trpc/client": "10.38.1",
|
||||||
"@trpc/server": "10.37.1"
|
"@trpc/server": "10.38.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,21 +2,21 @@
|
|||||||
"name": "playground",
|
"name": "playground",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "nuxt build",
|
"build": "nuxi build",
|
||||||
"dev": "nuxt dev",
|
"dev": "nuxi dev",
|
||||||
"generate": "nuxt generate",
|
"generate": "nuxi generate",
|
||||||
"preview": "nuxt preview",
|
"preview": "nuxi preview",
|
||||||
"postinstall": "nuxt prepare"
|
"postinstall": "nuxi prepare"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@trpc/client": "^10.37.1",
|
"@trpc/client": "10.38.1",
|
||||||
"@trpc/server": "^10.37.1",
|
"@trpc/server": "10.38.1",
|
||||||
"superjson": "^1.13.1",
|
"superjson": "^1.13.1",
|
||||||
"trpc-nuxt": "workspace:*",
|
"trpc-nuxt": "workspace:*",
|
||||||
"zod": "^3.21.4"
|
"zod": "^3.22.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.4.2",
|
"@types/node": "20.5.7",
|
||||||
"nuxt": "3.6.5"
|
"nuxt": "3.7.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createNuxtApiHandler } from 'trpc-nuxt'
|
import { createNuxtApiHandler } from 'trpc-nuxt'
|
||||||
import { appRouter } from '@/server/trpc/routers'
|
import { appRouter } from '../../trpc/routers'
|
||||||
import { createContext } from '@/server/trpc/context'
|
import { createContext } from '../../trpc/context'
|
||||||
|
|
||||||
export default createNuxtApiHandler({
|
export default createNuxtApiHandler({
|
||||||
router: appRouter,
|
router: appRouter,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
import { publicProcedure, router } from '../trpc'
|
import { publicProcedure, router } from '../trpc'
|
||||||
|
import { $fetch } from 'ofetch'
|
||||||
|
|
||||||
const baseURL = 'https://jsonplaceholder.typicode.com'
|
const baseURL = 'https://jsonplaceholder.typicode.com'
|
||||||
|
|
||||||
|
|||||||
3
playground/server/tsconfig.json
Normal file
3
playground/server/tsconfig.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "../.nuxt/tsconfig.server.json"
|
||||||
|
}
|
||||||
3281
pnpm-lock.yaml
generated
3281
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -14,6 +14,7 @@ function customFetch(input: RequestInfo | URL, init?: RequestInit & { method: 'G
|
|||||||
})
|
})
|
||||||
.then(response => ({
|
.then(response => ({
|
||||||
...response,
|
...response,
|
||||||
|
headers: response.headers,
|
||||||
json: () => Promise.resolve(response._data)
|
json: () => Promise.resolve(response._data)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user