Skip to content

Commit

Permalink
change add headers
Browse files Browse the repository at this point in the history
  • Loading branch information
evertonvargasvtex committed Oct 25, 2024
1 parent 39d3be6 commit d0658a1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 1 addition & 4 deletions packages/api/src/platforms/vtex/clients/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ interface FetchAPIOptions {
export const fetchAPI = async (
info: RequestInfo,
init?: RequestInit,
options?: FetchAPIOptions,
segmentCookie?: string | null
options?: FetchAPIOptions
) => {
const response = await fetch(info, {
...init,
headers: {
...(init?.headers ?? {}),
'User-Agent': USER_AGENT,
...(segmentCookie ? { Cookie: `vtex_segment=${segmentCookie}` } : {}),
},
})

Expand All @@ -35,4 +33,3 @@ export const fetchAPI = async (

throw new Error(text)
}

13 changes: 10 additions & 3 deletions packages/api/src/platforms/vtex/clients/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,18 @@ export const IntelligentSearch = (

console.log("search", segmentCookie)

const headers = segmentCookie
? {
headers: {
'Cookie': `vtex_segment=${segmentCookie}`,
},
}
: undefined

return fetchAPI(
`${base}/_v/api/intelligent-search/${type}/${pathname}?${params.toString()}`,
undefined,
{ storeCookies},
segmentCookie
headers,
{ storeCookies}
)
}

Expand Down
1 change: 1 addition & 0 deletions packages/api/src/platforms/vtex/resolvers/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { SearchArgs } from '../clients/search'

export const Query = {
product: async (_: unknown, { locator }: QueryProductArgs, ctx: Context) => {
console.log("product faststore", ctx)
// Insert channel in context for later usage
const channel = findChannel(locator)
const locale = findLocale(locator)
Expand Down

0 comments on commit d0658a1

Please sign in to comment.