@@ -23,19 +23,23 @@ import { resolveConfig } from './config.js';
23
23
* @param {Config } config
24
24
*/
25
25
async function fetchProductCS ( sku , config ) {
26
+ const { catalogEndpoint = 'https://catalog-service.adobe.io/graphql' } = config ;
26
27
const query = getProductQueryCS ( { sku } ) ;
27
-
28
- const resp = await fetch ( `https://catalog-service.adobe.io/graphql?query=${ encodeURIComponent ( query ) } ` , {
28
+ const resp = await fetch ( `${ catalogEndpoint } ?query=${ encodeURIComponent ( query ) } ` , {
29
29
headers : {
30
- origin : 'https://api.adobecommerce.live' ,
30
+ origin : config . origin ?? 'https://api.adobecommerce.live' ,
31
31
'x-api-key' : config . apiKey ,
32
32
'Magento-Environment-Id' : config . magentoEnvironmentId ,
33
33
'Magento-Website-Code' : config . magentoWebsiteCode ,
34
34
'Magento-Store-View-Code' : config . magentoStoreViewCode ,
35
+ 'Magento-Store-Code' : config . magentoStoreCode ,
35
36
} ,
36
37
} ) ;
37
38
if ( ! resp . ok ) {
38
39
console . warn ( 'failed to fetch product: ' , resp . status , resp . statusText ) ;
40
+ try {
41
+ console . info ( 'body: ' , await resp . text ( ) ) ;
42
+ } catch { /* noop */ }
39
43
throw errorWithResponse ( resp . status , 'failed to fetch product' ) ;
40
44
}
41
45
@@ -66,15 +70,19 @@ async function fetchProductCore(opt, config) {
66
70
67
71
const resp = await fetch ( `${ config . coreEndpoint } ?query=${ encodeURIComponent ( query ) } ` , {
68
72
headers : {
69
- origin : 'https://api.adobecommerce.live' ,
73
+ origin : config . origin ?? 'https://api.adobecommerce.live' ,
70
74
'x-api-key' : config . apiKey ,
71
75
'Magento-Environment-Id' : config . magentoEnvironmentId ,
72
76
'Magento-Website-Code' : config . magentoWebsiteCode ,
73
77
'Magento-Store-View-Code' : config . magentoStoreViewCode ,
78
+ 'Magento-Store-Code' : config . magentoStoreCode ,
74
79
} ,
75
80
} ) ;
76
81
if ( ! resp . ok ) {
77
82
console . warn ( 'failed to fetch product: ' , resp . status , resp . statusText ) ;
83
+ try {
84
+ console . info ( 'body: ' , await resp . text ( ) ) ;
85
+ } catch { /* noop */ }
78
86
throw errorWithResponse ( resp . status , 'failed to fetch product' ) ;
79
87
}
80
88
@@ -99,19 +107,24 @@ async function lookupProductSKU(urlkey, config) {
99
107
const query = getProductSKUQuery ( { urlkey } ) ;
100
108
const resp = await fetch ( `${ config . coreEndpoint } ?query=${ encodeURIComponent ( query ) } ` , {
101
109
headers : {
102
- origin : 'https://api.adobecommerce.live' ,
110
+ origin : config . origin ?? 'https://api.adobecommerce.live' ,
103
111
'x-api-key' : config . apiKey ,
104
112
'Magento-Environment-Id' : config . magentoEnvironmentId ,
105
113
'Magento-Website-Code' : config . magentoWebsiteCode ,
106
114
'Magento-Store-View-Code' : config . magentoStoreViewCode ,
115
+ 'Magento-Store-Code' : config . magentoStoreCode ,
107
116
} ,
108
117
} ) ;
109
118
if ( ! resp . ok ) {
110
119
console . warn ( 'failed to fetch product sku: ' , resp . status , resp . statusText ) ;
120
+ try {
121
+ console . info ( 'body: ' , await resp . text ( ) ) ;
122
+ } catch { /* noop */ }
111
123
throw errorWithResponse ( resp . status , 'failed to fetch product sku' ) ;
112
124
}
113
125
114
126
const json = await resp . json ( ) ;
127
+ console . log ( 'json: ' , JSON . stringify ( json , undefined , 2 ) ) ;
115
128
try {
116
129
const [ product ] = json . data . products . items ;
117
130
if ( ! product ) {
@@ -193,6 +206,7 @@ export default {
193
206
try {
194
207
const overrides = Object . fromEntries ( ctx . url . searchParams . entries ( ) ) ;
195
208
const config = await resolveConfig ( ctx , tenant , overrides ) ;
209
+ console . debug ( 'resolved config: ' , JSON . stringify ( config , undefined , 2 ) ) ;
196
210
if ( ! config ) {
197
211
return errorResponse ( 404 , 'config not found' ) ;
198
212
}
0 commit comments