Ionic 2 communication problem with mLab on Heroku

I’m writing an Ionic 2 application that communicates with a node server and mLab database on Heroku. Unfortunately when I try to send any request from the Ionic application I get errors that look like this.

Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8100’ is therefore not allowed access. The response had HTTP status code 503.

I have tried changing the headers around on the node heroku server


var cors = require(‘cors’);

app.use(cors());

app.use(function(req, res, next) {
res.header(“Access-Control-Allow-Origin”, “*”);
res.header(“Access-Control-Allow-Headers”, “Origin, X-Requested-With, Content-Type, Accept”);
next();
});

but no dice.

If you have any advice I would really appreciate it.

It’s because your using a local server. When I ran into this problem I just did a Google search for No ‘Access-Control-Allow-Origin’ and found a good bit of info on stackoverflow about how to work around it. For me that involved disabling certain security measures on chrome, but depending on your setup it maybe different for you.

1 Like

Thanks for the help!!!
I have the application working now.
Turning that plugin on gave me some new errors.
I used heroku log and found out I had git ignoring my node_moduals and the server was never working in the first place.

Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!