In my Vue app I’m Prismic CMS to host my products and therefore have to use a JSON crawler for validation.
My crawler works fine when viewing in the browser e.g. when I visit ‘https://…com/.netlify/functions/crawler’ so I see no problem with the JSON returned. But it doesn’t work in the checkout or when fetching products in the Snipcart dashboard…
Seriously need some help with this one
`const Prismic = require(’@prismicio/client’)
exports.handler = async () => {
try {
const client = Prismic.client(‘http://my-repo.cdn.prismic.io/api’)
return client
.query(Prismic.Predicates.at(‘document.type’, ‘shop_item’)) // An empty query will return all the documents
.then(function (response) {
let newItems = Object.values(response.results).map(item => {
return {
id: item.id,
title: item.data.shop_item.product_name.value[0].text,
price: item.data.shop_item.product_price.value
}
})
return {
statusCode: 200,
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(newItems)
}
})
} catch (error) {
console.log(error);
return {
statusCode: 500,
body: JSON.stringify({ error: ‘Failed fetching data’ }),
};
}
}
`