Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

303
Vistas
JS can't receive JSON data from orion-ld broker, a CORS related issue occurred

I use orion-ld context broker

{
"orionld version": "post-v1.0.0",
"orion version": "1.15.0-next",
"uptime": "0 d, 0 h, 25 m, 17 s",
"git_hash": "nogitversion",
"compile_time": "Wed Jan 26 15:58:47 UTC 2022",
"compiled_by": "root",
"compiled_in": "",
"release_date": "Wed Jan 26 15:58:47 UTC 2022",
"doc": "https://fiware-orion.readthedocs.org/en/master/"
}

If I try to request JSON data in an HTML file via JS like

var myRequest = new XMLHttpRequest();
myRequest.open("GET", "http://192.168.0.18:1028/ngsi-ld/v1/entities/urn:ngsi-ld:OffStreetParking:XXX_102700") ;
myRequest.setRequestHeader("Accept", "application/ld+json")       
myRequest.onload = function () {
    console.log(myRequest.responseText);
};
myRequest.send();

I got a error: "Access to XMLHttpRequest at 'http://192.168.0.18:1028/ngsi-ld/v1/entities/urn:ngsi-ld:OffStreetParking:XXX_102700' from origin 'http://192.168.0.18' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."

If I login to the docker container console and check the variable ORIONLD_CORS_ALLOWED_ORIGIN, it contains the necessary value "__ALL".

What could be wrong here?

Update at 03/01/2022: Now I create a simple webpage based on JS functions from NGSI.js, as Jason Fox yesterday suggested. There you are able to test the "v2" related calls to the orion-ld and the "ld" related calls. In the browser console, you can see the logged results. You can also change the orion-ld URL on the website so that you can test your environment. Nevertheless, the CORS settings for orion-ld server did not work as expected. 'v2' calls work well, 'ld' calls failed. I create my orion-ld test environment with the following docker-compose.yml:

version: "3.5"
services:
  orion-ld:
    image: fiware/orion-ld
    hostname: orion-ld
    ports:
      - "1029:1026"
    depends_on:
      - mongo-db  
    environment:
      ORIONLD_CORS_ALLOWED_ORIGIN: __ALL
      corsOrigin: __ALL
      ORIONLD_CORS_MAX_AGE: 86400
    command: -dbhost mongo-db-vm -logLevel DEBUG

  mongo-db:
    image: mongo:3.6 
    hostname: mongo-db-vm
    volumes:
      - /SOMEWHERE/data:/data

Please test my and your environment on simple webpage and give feedback.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Orion-LD architect and developer here. All Orion-LD has about CORS is what was inherited from Orion. This is the first time anybody asks for CORS for Orion-LD, so, I'll try to fix it asap.

about 4 years ago · Juan Pablo Isaza Denunciar

0

I guess this is all about a local development setup. Thus you probably call your frontend at "localhost" or "127.0.0.1", leading to the CORS-issue when it calls orion at "192.168.0.18". You basically have 2 options to still make it work:

  1. disable CORS in your browser when developing. Concrete solution depends on your browser.
  2. Put Orion-LD on localhost, thus calling it with the same origin as your frontend. The docker-compose snippet that you posted already puts orion on "localhost:1029"/"127.0.0.1:1029"(see ports-section). Thus, you should configure the orion endpoint in your frontend to "localhost:1029"/"127.0.0.1:1029"(depending on the address you use when calling orion) instead of the current container-ip(e.g. "192.168.0.18:1028")

I do not think it worth implementing the CORS-support directly in Orion-LD, since this is not a real deployment scenario. In real-world scenarios, you would have one of the following:

  1. A very small scenario, that does not even use any kind of security framework and only one broker instance. In such environments, its very unusual to have the frontend running on a different origin.
  2. A security framework between orion and the frontend. In this case, the requests from the frontend will never directly reach the broker, but the security-layer instead. Thus, the security component has to provide the CORS-header.
  3. A scenario with any kind of additional infrastructure(most probably a load-balancer or f.e. an lb+an ingress controller in k8s-environemnts). Similar to scenario 2, this would lead to no request directly reaching the broker and the component between frontend and broker needs to handle CORS.
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda