So, I have both a website and an API configured locally in Docker, that way I can test the site locally and the API too. But the thing is, I have a piece of code in my local machine (not Docker) that I’m trying to use to make some calls to the local API in Docker.
My issue is, when I run my code with vscode, the API requests keep failing and throwing the error: 401 unauthorized. After debugging the request and comparing to the one made in the working site, I find that the only difference between requests is that the origin in the working page it’s the domain itself, while the origin in my local code is my locahost.
I believe this it what is causing the request to fail (could be that the API creators don’t allow CORS), so I’m trying to make it so my local code has the same origin as my docker systems.
Do you guys have any idea on how I could do it?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
New accounts only. By submitting your email you agree to our Privacy Policy.
Hello @d7abec53c19a47d9b0688f32882e83
The 401 Unauthorized response status code usually indicates the the request lacks valid authentication credentials for the requested resource.
In this case since it is API request this can be the secret key, API client keys, tokens and any URLs or domains.
I would recommend to check if the specified credentials are valid/working as this will be my starting point if I was into the same situation.
Hope that this helps!