I’ve encountered a problem with my app on Heroku located at . It uses Mandrill to send emails. Whether I run the app locally using localhost:5000
or remotely on Heroku, I encounter the following error when attempting to send emails:
XMLHttpRequest cannot load . Response to preflight request doesn't pass access control check: A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin '' is therefore not allowed access.
I’ve searched extensively on Stack Overflow for solutions (refer to CORS: Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true), and have accordingly configured my express headers as follows:
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "http://localhost:5000 http://random-name.herokuapp.com");
res.header('Access-Control-Allow-Credentials', true);
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
Despite these adjustments, the issue persists. I couldn’t find any helpful guidance in Mandrill’s documentation either. It’s possible that I’m setting the headers incorrectly, or they may not be taking effect at all. Any suggestions?