Custom Action Opens a Preview URL on Wrong Domain
17 replies
Last updated: Jan 31, 2022
N
Hey there, I have a custom action that opens a preview URL, but it keeps opening my URL at the studio domain, instead of the one specified…
Jan 31, 2022, 6:46 PM
N
Jan 31, 2022, 6:46 PM
N
You can see it here, it’s supposed to use the
remoteURLbut on deployed studios it’s now opening it without this, causing it to open the
/api/preview?token=xxxat the studio domain
Jan 31, 2022, 6:47 PM
N
sorry, wrong example
user A
, I just updated it with a gist of the correct one.Jan 31, 2022, 6:47 PM
N
I have a client studio that has this:
Jan 31, 2022, 6:48 PM
N
const remoteURL = '<https://xxx.vercel.app>' const localURL = '<http://localhost:3000>' const frontendURL = window.location.hostname === 'localhost' ? localURL : remoteURL
Jan 31, 2022, 6:48 PM
N
and it’s opening it at
<https://xxx.sanity.studio>
Jan 31, 2022, 6:48 PM
E
Don't suppose there is any chance you are viewing it from
127.0.0.1or
0.0.0.0or some other local, non-localhost hostname? 😅
Jan 31, 2022, 7:30 PM
E
(maybe
window.location.protocol === 'http:' ? localURL : remoteURLwould be slightly more robust in this case?)
Jan 31, 2022, 7:31 PM
N
seems to only be on a deployed studio for some reason
Jan 31, 2022, 7:32 PM
E
How is the
remoteURLgetting set? Statically? Environment variable?
Jan 31, 2022, 7:32 PM
N
going to try clearing node_modules and dist to see if it helps!
Jan 31, 2022, 7:32 PM
N
static
Jan 31, 2022, 7:33 PM
E
Super weird. There is nothing Sanity-specific about the code that determines the URL or opens the window, as far as I can tell from your gist.
Jan 31, 2022, 7:34 PM
E
If I were to guess, the
remoteURLis somehow null/empty string, but if it's defined statically that doesn't make sense
Jan 31, 2022, 7:35 PM
N
thanks for clarifying
user Z
! I’m wondering if checking localhostis for whatever reason erroring when deploying
Jan 31, 2022, 7:35 PM
N
I just redeployed again, and hard refreshed and this time it’s taking the correct domain name
Jan 31, 2022, 7:36 PM
N
it’s just super odd since I was able to reproduce on the deployed studio after the client alerted me to it (which I had just showed them how to preview last week using the deployed studio during a previous build)
Jan 31, 2022, 7:36 PM
Sanity.io – build remarkable experiences at scale
Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.