setPreviewData() works for Amplify domain but not custom domain
Unanswered
Giant panda posted this in #help-forum
Giant pandaOP
I have have a Next (v12.3.4) app running on Amplify and have implemented an API route that calls
It works fine on the https://main.amplifyid.amplifyapp.com domain but not on the custom domain that I have setup in my CDN.
I need it to work on the custom domain ( https://custom.mysite.com ) so that the site can make API calls which are sitting on another origin.
I can see that the
When it returns the response with the
If I add a query string to the URL then Next will also add the query string to the request to
Unfortunately it's hard to see what is happening in Amplify.
setPreviewData()It works fine on the https://main.amplifyid.amplifyapp.com domain but not on the custom domain that I have setup in my CDN.
I need it to work on the custom domain ( https://custom.mysite.com ) so that the site can make API calls which are sitting on another origin.
I can see that the
_next_preview_data and __prerender_bypass cookies are being set and sent when browsing on the custom domain but for some reason the call to get the pageProps from the server ( https://custom.mysite.com/_next/data/buildid_ver/en-AU/au.json ) is returning a http header x-nextjs-cache set to HIT while browsing on the Amplify domain it is returning x-nextjs-cache set to MISS.When it returns the response with the
x-nextjs-cache set to HIT it is not including the __N_Preview property in the JSON response. It only has the __N_SSG set to true and it also doesn't include anything in the pageProps.previewData.If I add a query string to the URL then Next will also add the query string to the request to
/_next/data/... (e.g. https://custom.mysite.com/_next/data/buildid_ver/en-AU/au.json?query=true) which will then cause a cache miss and the correct response including __N_Preview and the pageProps.previewData set correctly.Unfortunately it's hard to see what is happening in Amplify.