Question

docker is running an internal network, but on droplet gets CORS errors

I am using a droplet as a dev environment for a dockerized application (node, nginx, postgresql, graphql, react). Our docker app sets up an internal network so that different components can communicate with each other. The docker container builds and runs great, but internal calls from the frontend to the backend are getting blocked in the droplet based on CORS errors.

We can run this thing literally everywhere else with no CORS errors - are there droplet-specific settings I need to create?

Subscribe
Share

ugh, there’s also an issue with the dockerized instance of the database being built under user ‘systemd-coredump’ rather than the user that everything else is built under.


Submit an 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.

Hello,

There are no Droplet specific settings. This would happen if the API is running on a different port so that the request origin would not match. Can you share the exact CORS error that you are getting?

You cat add a Access-Control-Allow-Origin to your Node.js app so that it would accept the requests:

app.use(function(req, res, next) {
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
    res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
    res.setHeader('Access-Control-Allow-Credentials', true);
    next();
});

Let me know how it goes. Best, Bobby