I got CORS error when trying to do a request in my app in Heroku

46 views Asked by At

This is the error that I had faced before when requesting in localhost, and I solved it using proxy config in Angular.

So as I was using a custom proxy, I had to remove that proxy-config from my Angular app before deploying it in Heroku, because if I don't do this, the deployment app doesn't work.

This is the CORS error:

cors error

in postman the localhost request works if I nodemon the node server so I can say there's no error in my api

postman request

but if using the request given by heroku in postman I get this html response

heroku link in postman

tbh I don't know what's going on, because I'm doing a course of Angular and these errors are not supposed to appair, tkank you guys :)

1

There are 1 answers

1
Evgheni Calcutin On

Your web server should allow cors for you application.

If you server is written with NodeJS, take look at the Cors package

Then In NodeJS project, install it:

npm install cors

Then modify a bit your listener:

var cors = require('cors')
app.use(cors())

Make sure app.use(cors()) to be before any other middleware