-1

Here's the situation:

I have a client application (Angular 8/Ionic 4) that is calling a API (Loopback) with a PATCH.

I listen to the "after save" hook of a certain model, which the datasource is PostgreSQL. When this hook gets triggered, I call a model that the datasource is MongoDB to perform an UpsertWithWhere operation in this MongoDB model.

The problem is that I get the following error with code 502:

Access to XMLHttpRequest at 'https://dev-api.celsoonline.com.br/api/v2/Encontros' from origin 'http://dev-aluno.celsoonline.com.br' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

So, you might think: "Missing cors configuration". But It's not. I have already configured it, in 3 different locations:

1 - server.js

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

2 - middleware.json

"cors": {
 "params": {
    "origin": true,
    "credentials": true
  }
}

3 - config.json

"remoting": {cors: true}

The MongoDB is at the Atlas server, with network access allowed to all IPs (0.0.0.0/0)

Can anyone help me on this? I'm currently working on a dev environment hosted on AWS. Running locally the error do not occur.

What am I missing?

Thanks!

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
  • What’s the HTTP status code of the response? You can use the Network pane in browser devtools to check. Is it a 4xx or 5xx error rather than a 200 OK success response? – sideshowbarker Oct 11 '19 at 10:32
  • It`s a 502 code – Gabriel Cabral Oct 12 '19 at 17:26
  • Th 502 (Bad Gateway) error is the actual problem that needs to be fixed. If you fix that, you’re likely going to find that your existing CORS config is already working as expected. The only reason the browser is logging that CORS message is that a 502 error is never going to include CORS headers. – sideshowbarker Oct 12 '19 at 22:52

2 Answers2

-1

Sometimes firewall issue happens so ones more check your IP in AWS

shiva
  • 209
  • 2
  • 5
-1

Work on the same domain to avoid CORS rules or disable CORS in browser (eg plugin in Firefox)

Other than that, follow on how to setup CORS on server.js https://github.com/expressjs/cors

 "origin": true,

it should be false to disable CORS check

Antoniossss
  • 31,590
  • 6
  • 57
  • 99