Hi, @ismailp. Looking at your code, overall I think you are doing it correctly. One thing I noticed though is in the fetch you are using a relative url. The url needs to include the domain of your API as well so Builder can make the fetch call. Can you try await fetch('https://www.thedomainofyourapi.com/api/product?sku=MY_SKU')?
That will not work, because localhost is not accessible on the public internet by the Builder servers. For now, you probably want to remove the Builder.isServer code and let the fetch happen client side, where the code will have access to your local server. Then, when you have deployed your API code, you can add back in the isServer check if you want to.
async function main() {
await fetch('https://hs-git-product-api-endpoint.mersenne.now.sh/api/product-widget?sku=LEATHER_PURSE-BLACK_LANDSCAPE')
.then(res => res.json())
.then(data => {
console.log(data);
// set the data on the state object so you can access it from your components
state.product = data;
});
}
export default main();
@ismailp, I just took a closer look and I am not sure exactly why the code is not setting state on the server. However, I think it might be a bug that will take some more time to investigate. Hopefully you can use the client side solution for now, and I will let you know when we fix the issue.
We released a fix earlier for the API side, I’m still seeing an issue where only when you’re editing the ssr content is not hydrated properly, I’m investigating this, but otherwise live content should be fixed.
It’s not working. I have a custom function that updates the state. This function should be run on the server side. It’s not so this is still an issue @aziz