CORS error during API call in different domain

Hi everyone

I am getting CORS policy error during API call in different domain where I hosted my front end. actually my openremote deployed on different server and static IP, our frontend deployed on different server and domain, so we are facing CORS error. How can I resolve this error?

What is the exact CORS error you are getting?
And of course when are you getting the error? On a HTTP API call to manager or keycloak,
visiting the manager UI, or when trying to authenticate, … ?

Could be that it is related to your deployments, especially if one has a static IP and
the other a domain. Are you using SSL by any chance? If so, on which servers is it active?

Hi Martin,

Both on same server using static IP… following is the error while calling GET api to see the asset attribute’s data.

As mentioned in the error: “Redirect is not allowed for a preflight request

I don’t know what your exact deployment looks like of course, but just checking;
The request URL doesn’t have a port specified like 8080, or is the manager hosted on port 80?

The error sounds like a simple deployment issue though…
You probably tested this beforehand using a REST client like postman… If not, try that haha
Do you mind sharing deployment details such as a docker-compose file?

Please see the docker compose file:

# OpenRemote v3
#
# Profile that runs the stack by default on https://localhost using a self-signed SSL certificate,
# but optionally on https://$OR_HOSTNAME with an auto generated SSL certificate from Letsencrypt.
#
# It is configured to use the AWS logging driver.
#
version: '2.4'

volumes:
  proxy-data:
  manager-data:
  postgresql-data:

services:

  proxy:
    image: openremote/proxy:${PROXY_VERSION:-latest}
    restart: always
    depends_on:
      manager:
        condition: service_healthy
    ports:
      - "80:80"
      - "${OR_SSL_PORT:-443}:443"
      - "8883:8883"
      - "90:90"
    volumes:
      - proxy-data:/deployment
    environment:
      LE_EMAIL: ${OR_EMAIL_ADMIN:-}
      DOMAINNAME: ${OR_HOSTNAME:-198.177.125.69}
      DOMAINNAMES: ${OR_ADDITIONAL_HOSTNAMES:-}
      # USE A CUSTOM PROXY CONFIG - COPY FROM https://raw.githubusercontent.com/openremote/proxy/main/haproxy.cfg
      #HAPROXY_CONFIG: '/data/proxy/haproxy.cfg'

  postgresql:
    restart: always
    image: openremote/postgresql:${POSTGRESQL_VERSION:-latest}
    volumes:
      - postgresql-data:/var/lib/postgresql/data
      - manager-data:/storage

  keycloak:
    restart: always
    image: openremote/keycloak:${KEYCLOAK_VERSION:-latest}
    depends_on:
      postgresql:
        condition: service_healthy
    volumes:
      - ./deployment:/deployment
    environment:
      KEYCLOAK_ADMIN_PASSWORD: ${OR_ADMIN_PASSWORD:-secret}
      KC_HOSTNAME: ${OR_HOSTNAME:-198.177.125.69}
      KC_HOSTNAME_PORT: ${OR_SSL_PORT:--1}


  manager:
#    privileged: true
    restart: always
    image: openremote/manager:${MANAGER_VERSION:-latest}
    depends_on:
      keycloak:
        condition: service_healthy
    environment:
      OR_SETUP_TYPE:
      OR_ADMIN_PASSWORD:
      OR_SETUP_RUN_ON_RESTART:
      OR_EMAIL_HOST:
      OR_EMAIL_USER:
      OR_EMAIL_PASSWORD:
      OR_EMAIL_X_HEADERS:
      OR_EMAIL_FROM:
      OR_EMAIL_ADMIN:
      OR_HOSTNAME: ${OR_HOSTNAME:-198.177.125.69}
      OR_ADDITIONAL_HOSTNAMES: ${OR_ADDITIONAL_HOSTNAMES:-}
      OR_SSL_PORT: ${OR_SSL_PORT:--1}
      OR_DEV_MODE: ${OR_DEV_MODE:-false}

      # The following variables will configure the demo
      OR_FORECAST_SOLAR_API_KEY:
      OR_OPEN_WEATHER_API_APP_ID:
      OR_SETUP_IMPORT_DEMO_AGENT_KNX:
      OR_SETUP_IMPORT_DEMO_AGENT_VELBUS:
    volumes:
      - manager-data:/storage
      - ./deployment:/deployment

Just to confirm here;
This is an issue on your own end, not OpenRemote related neccesairly.

First check whether the API is available through port 80 or if you force https like 443.
Or try sending a head request to see whether the preflight succeeds.
You can always bypass the proxy as a temporary solution by exposing the ports on the manager container.

But I think this is something you need to research yourself sadly

Thank you Martin,

I am trying to understand, can you please tell me how to know that https (port 443) force or not?

What is the meaning of " OR_SSL_PORT: ${OR_SSL_PORT:–1} "

To temporary bypass proxy mean, shall I expose port 80 into manager container or the port from which I am trying to fetch API ( let’s say port 3000)?