I built a MERN app, and I deployed the REACT client into Netlify. The server side is deployed at Railway.app (Node.js + Express), and I use MongoDB Atlas Cloud. Everything works fine using my macOS Chrome browser. When I tried to use my iPhone browser, I had an exception in Node.js console saying, “UnauthorizedError: No authorization token was found.” If I turn off the iPhone option “Allow Cross-Site tracking,” it works. So, clearly, Netlify is not redirecting correctly. My netlify.toml file is placed in my client/src folder (same place as the package.json file), and the file content is:
[[redirects]]
from = "/api/*"
to = "https://myapp-production.up.railway.app/:splat"
status = 200
force = true # COMMENT: ensure that we always redirect
signed = "TOKEN_SECRET"
The TOKEN_SECRET is an environment variable configured inside Netlify Environment Variables that matches my token secret. I also have a file called _redirects, placed under my public folder (client/public) with this content:
So… what’s the answer? I removed now the _redirects file and inserted into the netlify.toml file
[[redirects]]
from = "/api/*"
to = "https://bedtimeserver-production.up.railway.app/:splat"
status = 200
force = true # COMMENT: ensure that we always redirect
signed = "TOKEN_SECRET"
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
Same exactly error. I can’t get through my tokenized end points. What’s the solution?
We replied to a support ticket about this as well. I’m copying our answer there to share it with anyone finding this topic in a search:
It’s important to note that we don’t send the token through. What the signed setting is for is signing the JSON Web Signature. This is mentioned in Netlify docs here:
You are of course welcome to interpret the situation however you want. I don’t see anyplace where we’ve told you you can’t do that, and while it’s not a normal use case to host an express app here, it is possible:
I don’t see how your specific server not handling JWS requests makes it impossible to do anything, but I could be missing something too.
I think that if you are trying to send the token, you’d want to use a different feature, either this one which literally sends the token as a header: