How can I make it so my local code is in the same origin as my apps in Docker?

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?

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Site Moderator
Site Moderator badge
January 24, 2023

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!

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel
Get started for free

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.

© 2023 DigitalOcean, LLC.