Nodejs express, Heroku CORS Nodejs express, Heroku CORS express express

Nodejs express, Heroku CORS


Try to also allow the credentials:

app.use(function(req, res, next) {    res.header("Access-Control-Allow-Origin", '*');    res.header("Access-Control-Allow-Credentials", true);    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');    res.header("Access-Control-Allow-Headers", 'Origin,X-Requested-With,Content-Type,Accept,content-type,application/json');    next();});

Edit:

Also if you want to make a local http call in your heroku app;change

private url = 'https://myserver.herokuapp.com/';

to

private url = '/';


Hi I worked out that it was due to Heroku will only install packeges from your dependancies

And what I needed was in my devDependencies, so once I reinstalled as dependancies it worked!


another possible cause is missing .env variables. When deploying a heroku server, all .env variables have to be set via heroku's config vars.

If the route required a missing .env, for some reason it returns as a CORS error.

In my case, the jsonwebtoken was looking for process.env.secretkey, so all routes that called for the jsonwebtoken returned with CORS error, while routes that does not require it worked just fine.