mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-14 20:19:33 +01:00
42 lines
717 B
Markdown
42 lines
717 B
Markdown
---
|
|
title: Headers
|
|
---
|
|
|
|
# Headers
|
|
|
|
We can use the built-in `useRequestHeaders` to set outgoing request headers:
|
|
|
|
```ts [plugins/client.ts]
|
|
export default defineNuxtPlugin(() => {
|
|
const headers = useRequestHeaders()
|
|
|
|
const client = createTRPCProxyClient<AppRouter>({
|
|
links: [
|
|
httpBatchLink({
|
|
// headers need to be a function so it gets called dynamically
|
|
// every HTTP request
|
|
headers() {
|
|
return {
|
|
...headers
|
|
}
|
|
}
|
|
}),
|
|
],
|
|
})
|
|
|
|
return {
|
|
provide: {
|
|
client,
|
|
},
|
|
}
|
|
})
|
|
```
|
|
|
|
```ts [server/trpc/context.ts]
|
|
export function createContext (event: H3Event) {
|
|
console.log('cookies', parseCookies(event))
|
|
|
|
return {}
|
|
}
|
|
```
|