Here is an example of the CORS error (same error for any of my endpoints):
Access to fetch at ‘https://buy-where.herokuapp.com/api/v1/auth_check’ from origin ‘https://buy-where.netlify.app’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.
One other thought: can you try deleting the localhost origin so that the line is just origins 'https://buy-where.netlify.app/' (so, no array) and seeing how that goes?
I just tried removing the localhost origin, and it didn’t affect (improve) the issue. About to read through the gotchas resource you just referenced. And thank you for responding and helping so quickly!
Just read through the gotchas, and looked at the middleware stack as suggested by the resource, and the positioning of Rack::Cors appears to be where the author suggests it is safest (positioned at the top of the stack)
@jen also, did I mention that it works totally fine when I fire up my development server?
http://localhost:3001/ is the url allowed in my cors.rb file, and I just fired it up, and it’s working perfectly. That leads me to believe my backend is configured correctly as well, but obvioulsy I could be wrong.
Ok this is interesting. I’ll see if I can figure out how to get the server to come from Heroku as well. Not entirely sure how to go about debugging this. But a great learning opportunity! Thank you for your continued help
Oh no! You’re right, that was my mistake. I’ll update the screen shot I posted above with one that’s instead a POST to Buy / Where. Either way, still no Access-Control-Allow-Origin header (or the other headers set in rack-cors and present in the memes-vs-gifs site request) in either of ours
Do I need to create a proxy with a netlify function? (I believe it’s something like that). I’ve never used Netlify functions before and I should probably learn them at some point. Is this a good use case for creating a proxy?
Hi, @jamesncox. I just tested the sign-up and I don’t see the CORS errors now.
Did you resolve the issue? If not, please let us know how to reproduce the error (or I’ll ask @jen how to do so).
On the other hand, if you did resolve it, please feel free to share the solution here as it may be helpful for another person searching for answers in the future.
Hi @luke, thank you for your response! The short answer is, YES. I resolved the issue.
The long and embarrassing answer is it was a VERY DUMB mistake on my Rails API side. You will notice a forward slash “/” appended to the URL in my cors.rb file that I shared as an image and code snippet above. That final forward slash was causing my actual site URL to be blocked.
I am so glad that it was that simple, but super embarrassed how much of my own and other’s time I wasted trying to figure this out. I guess the one good takeaway is I feel more confident than ever to try and build my first even Netlify function to try and hide a few secret API keys in other projects.
Thanks so much for sharing this! I was having the exact same issue with my rails API on Digital Ocean and removing the closing / from the URL fixed the issue!