Skip to content

Commit

Permalink
Merge pull request #109 from BearToCode/main
Browse files Browse the repository at this point in the history
docs: mention editing response headers
  • Loading branch information
icflorescu committed Feb 28, 2024
2 parents a6d241d + a693ab7 commit b48c7ef
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/src/routes/recipes-and-caveats/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const prerender = true;
export const load: PageServerLoad = () => ({
codeBlocks: loadCodeBlocks({
'bookstall/src/lib/trpc/router.ts': 'example',
'bookstall/src/routes/authors/+page.svelte': 'example'
'bookstall/src/routes/authors/+page.svelte': 'example',
'simple/src/lib/trpc/context.ts': 'example'
})
});
14 changes: 14 additions & 0 deletions docs/src/routes/recipes-and-caveats/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@
can be useful, for example, to set an <code>Authorization</code> header.
</p>

<h3>Setting response headers and cookies</h3>

<p>
To change the headers of the response, you want to use the <code>event</code> provided in
<code>getContext</code>. You may also pass the <code>event</code> into the context, so that it can
be accessed in your procedures.
</p>

<p>
You can then use <code>event.setHeaders</code> and <code>event.cookies</code> to edit the headers.
</p>

<Highlight {...data.codeBlocks['simple/src/lib/trpc/context.ts']} />

<h3>Using custom data transformers</h3>

<p>
Expand Down
5 changes: 1 addition & 4 deletions examples/simple/src/lib/trpc/context.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import type { RequestEvent } from '@sveltejs/kit';
import type { inferAsyncReturnType } from '@trpc/server';

// we're not using the event parameter is this example,
// hence the eslint-disable rule
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function createContext(event: RequestEvent) {
return {
// context information
event // 👈 `event` is now available in your context
};
}

Expand Down

0 comments on commit b48c7ef

Please sign in to comment.