From f5af99c6494ed20f7e1a42aa14539a65a32bfc44 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 9 Nov 2022 17:48:53 +0100 Subject: [PATCH 1/3] docs: get event before running async function --- docs/content/1.getting-started/6.data-fetching.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/content/1.getting-started/6.data-fetching.md b/docs/content/1.getting-started/6.data-fetching.md index 93c1f23484b..0dd0ac412e7 100644 --- a/docs/content/1.getting-started/6.data-fetching.md +++ b/docs/content/1.getting-started/6.data-fetching.md @@ -263,10 +263,11 @@ Here is a list of common headers that are NOT to be proxied: ```ts [composables/fetch.ts] export const fetchWithCookie = async (url: string) => { + const event = useRequestEvent() const res = await $fetch.raw(url) const cookies = (res.headers.get('set-cookie') || '').split(',') for (const cookie of cookies) { - appendHeader(useRequestEvent(), 'set-cookie', cookie) + appendHeader(event, 'set-cookie', cookie) } return res._data } From 88bc115c582961a3c57fb2b2b6d558f207cd2156 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 9 Nov 2022 17:56:29 +0100 Subject: [PATCH 2/3] docs: improve example --- docs/content/1.getting-started/6.data-fetching.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/content/1.getting-started/6.data-fetching.md b/docs/content/1.getting-started/6.data-fetching.md index 0dd0ac412e7..5556092cf05 100644 --- a/docs/content/1.getting-started/6.data-fetching.md +++ b/docs/content/1.getting-started/6.data-fetching.md @@ -238,9 +238,8 @@ The example below adds the request headers to an isomorphic `$fetch` call to ens ```vue ``` @@ -262,8 +261,7 @@ Here is a list of common headers that are NOT to be proxied: If you want to pass on/proxy cookies in the other direction, from an internal request back to the client, you will need to handle this yourself. ```ts [composables/fetch.ts] -export const fetchWithCookie = async (url: string) => { - const event = useRequestEvent() +export const fetchWithCookie = async (url: string, event: H3Event) => { const res = await $fetch.raw(url) const cookies = (res.headers.get('set-cookie') || '').split(',') for (const cookie of cookies) { @@ -276,7 +274,8 @@ export const fetchWithCookie = async (url: string) => { ```vue ``` From 8415e17d70f2e7ff79cd9c92ddfdbd1d0532e6a2 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 10 Nov 2022 10:19:35 +0100 Subject: [PATCH 3/3] docs: switch args --- docs/content/1.getting-started/6.data-fetching.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/content/1.getting-started/6.data-fetching.md b/docs/content/1.getting-started/6.data-fetching.md index 5556092cf05..ffde5f7279a 100644 --- a/docs/content/1.getting-started/6.data-fetching.md +++ b/docs/content/1.getting-started/6.data-fetching.md @@ -261,7 +261,7 @@ Here is a list of common headers that are NOT to be proxied: If you want to pass on/proxy cookies in the other direction, from an internal request back to the client, you will need to handle this yourself. ```ts [composables/fetch.ts] -export const fetchWithCookie = async (url: string, event: H3Event) => { +export const fetchWithCookie = async (event: H3Event, url: string) => { const res = await $fetch.raw(url) const cookies = (res.headers.get('set-cookie') || '').split(',') for (const cookie of cookies) { @@ -275,7 +275,7 @@ export const fetchWithCookie = async (url: string, event: H3Event) => { ```