Troubleshooting deployment and login issues with self-hosted Sanity instance

9 replies
Last updated: Feb 23, 2022
Running into some weird development and deployment issues with a self-hosted version of Sanity.So I have my studio deployed at a subdomain
<http://studio.mysite.com|studio.mysite.com>
and the site it serves content to @
<http://www.mysite.com|www.mysite.com>
.
I am using the
netlify/cli
to run a local dev instance which proxy's from a
targetPort: 3333
or the Sanity Studio application to the Netlify dev exposed
port: 9090
which is also setup as a CORS whitelisted URL on Sanity. This is supposed to mimic deployment on Netlify.
When I spin up Netlify Dev, the Studio app returns what's in the posted image, but still remains accessible at its application
port:3333
.
When it's deployed to Netlify itself, I am getting prompted for Sanity login that resolves to a
Page Not Found
message. In order to try an fix that, I have a
netlify.toml
files that does the redirects for SPA apps like so.

[[ redirects ]]
  from = "/*"
  to = "/index.html"
  status = 200
This still doesn't give me the expected result of being able to login to the
production
or
develop
instances of the studio app.I am bit stumped as to why this is not working as I feel I have had this setup the same way in past project tests. I have double checked all my CORS settings as well as my local configurations and still can't find a way to troubleshoot this.

Any help would be greatly appreciated.
Feb 17, 2022, 10:27 PM
Ok I got my production environment working by switching off my Brave browser shields. So effectively a cookie was stopping my
production
deploys, but I still can't figure out why my local Netlify Dev instance will gives me the
SyntaxError: Unexpected token '&lt;'
Feb 17, 2022, 11:32 PM
Hey Jonathon. You are redirecting all requests to
/index.html
. Based on the error, I'm guessing that Sanity is trying to load a JS or JSON file, but your server is instead providing
index.html
—which is not a valid script file.
That's just a guess
🙂. Are you able to see any more details in your console about which specific request or file is leading to this error?
Feb 18, 2022, 10:25 AM
Hey
user E
thanks for that! I turned off the redirects and it seemed to do the trick. For some reason I was getting a
Page Not Found
on Netlify and thought this
netlify.toml
might be the solution. I guess it wasn’t….😅
Thanks again!
Feb 18, 2022, 5:47 PM
Alright, so after deploying without the redirects.I pulls up the login to Sanity prompt, but when I click on my preferred login method, I get whats in the image.
Feb 18, 2022, 9:30 PM
Kind of stumped, not sure what’s going on exactly that makes it so I cannot login to my production instances, or develop instances. All my CORS origin settings are correct.
Feb 18, 2022, 9:38 PM
Ahh! Cookies once again! Shoot!
Feb 18, 2022, 9:41 PM
The redirect is required, but I initially wondered whether it was preventing other files from being served. I just checked the Netlify docs, and this is not the case. By default, a Netlify redirect will respect existing paths .
You do need the redirect. Removing it is probably why you're now getting a
404
after signing in.
Sorry for leading you down the wrong path, but at least we've now eliminated one possible cause of this issue
🙂.
The next questions I'd like to ask are:

1. Do you have the latest version of
the Netlify CLI installed?2. Does the
SyntaxError: Unexpected token '&lt;'
error occur both locally and on Netlify?3. Does the
SyntaxError: Unexpected token '&lt;'
error occur when running your Studio locally using the
sanity start
command (instead of using the Netlify CLI)?
Feb 21, 2022, 9:30 AM
Thanks for following up
user E
. Turned out to be aggressive Cookie blocking in Brave that was the issue. Seems to be working ok now.
Feb 22, 2022, 9:53 PM
Great, I'm glad you got this working! And I'm sorry for the cookie issues.
Feb 23, 2022, 10:35 AM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?