Skip to content

Commit

Permalink
fix(request-store-api): store id only on url when using cache api
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Jul 11, 2019
1 parent 3cc269c commit 761e278
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/methods/request-store-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,33 @@ const requestStoreApi = (
storeId = _config.get('store_id'),
axiosConfig
) => {
let timeout, baseURL
const headers = {
'X-Store-ID': storeId
}
let timeout, baseURL, headers

// first check if it's a public request
if (method.toLowerCase() === 'get' && !authenticationId) {
// less timeout for public requests
if (isCacheOnline && !/\?/.test(url) && (!axiosConfig || !axiosConfig.params)) {
// use cache API host
timeout = 2500
// Store ID on URL
baseURL = API_STORE_CACHE.replace(':id', storeId)
} else {
// set 5s default timeout on browser
timeout = IS_BROWSER ? 5000 : 30000
baseURL = API_STORE
// Store ID on header
headers = {
'X-Store-ID': storeId
}
}
} else {
baseURL = API_STORE
// setup authentication headers
headers['X-My-ID'] = authenticationId
headers['X-Access-Token'] = accessToken
headers = {
'X-Store-ID': storeId,
'X-My-ID': authenticationId,
'X-Access-Token': accessToken
}
}

// returns axios request promise
Expand Down

0 comments on commit 761e278

Please sign in to comment.