Nodejs fetch and Traefik

Hi Guys, we have a docker compose with a traefik (v2.11) as a proxy for multiple services (postgres, keycloak, api, front, ...)

I have a problem because a traefik hostname is accessible from the browser (nice) but not from a nodejs application that use fetch. As far as i known it's probably a DNS issue, but i can't find a way to resolve it.

http:
  routers:
    traefik:
      rule: "Host(`traefik.docker.localhost`)"
      service: "api@internal"
      tls:
        domains:
          - main: "docker.localhost"
            sans:
              - "*.docker.localhost"

tls:
  certificates:
    - certFile: "/etc/traefik/ssl/local-cert.pem"
      keyFile: "/etc/traefik/ssl/local-key.pem"
global:
  sendAnonymousUsage: false

api:
  dashboard: true
  insecure: true

providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    watch: true
    exposedByDefault: false

  file:
    filename: /etc/traefik/config.yml
    watch: true

log:
  level: INFO
  format: common

accessLog: {}

entryPoints:
  http:
    address: ":80"
    http:
      redirections:
        entryPoint:
          to: https
          scheme: https
  https:
    address: ":443"
  postgres:
    address: ":5432"

and the keycloak docker compose configuration

  keycloak:
    image: ${REGISTRY:-msdepi}/keycloak:${PLATFORM:-linux}-${TAG:-latest}
    profiles:
      - infra
    build: ./.local/.keycloak
    environment:
      KEYCLOAK_ADMIN: admin
      KEYCLOAK_ADMIN_PASSWORD: ${KEYCLOAK_ADMIN_PASSWORD}
      KC_DB: postgres
      KC_DB_URL_HOST: postgres
      KC_DB_USERNAME: postgres
      KC_DB_PASSWORD: ${POSTGRES_PASSWORD}
      KC_DB_URL_DATABASE: ${DB_NAME}
      KC_DB_SCHEMA: public
      KC_PROXY: edge
      KC_HTTP_ENABLE: true
      KC_HTTP_HOST: 0.0.0.0
      KC_HOSTNAME_STRICT: false
      KC_HOSTNAME: keycloak.docker.localhost
    command: start --import-realm
    volumes:
      - ./.local/.keycloak/realm-config/:/opt/keycloak/data/import/
    depends_on:
      postgres:
        condition: service_healthy
    labels:
      - "traefik.enable=true"
      - "traefik.http.services.keycloak.loadbalancer.server.port=8080"
      - "traefik.http.services.keycloak.entrypoints=http"
      - "traefik.http.routers.keycloak.rule=Host(`keycloak.docker.localhost`)"
      - "traefik.http.routers.keycloak.tls=true"

Whe using the fetch in node

fetch('https://keycloak.docker.localhost/')
  .then(resp => console.log(resp))
  .catch(err => console.error(err))

i have this error

TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11457:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  cause: Error: getaddrinfo ENOTFOUND keycloak.docker.localhost
      at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26) {
    errno: -3008,
    code: 'ENOTFOUND',
    syscall: 'getaddrinfo',
    hostname: 'keycloak.docker.localhost'
  }
}

which just says that it can't resolve the domain name

Did you configure those domains in your local hosts file or on your DSL router?

No, but the keycloak.docker.localhost is acessible from the browser without any issue but not from node. Which i need to authenticate my user from the NextJs application

Some browsers are automatically resolving any *.localhost to 127.0.0.1. Node will not do that.

ok thanks.
So if i have everything inside docker, will node be able to resolve the domain name through the docker dns ?

Not with localhost, but with service/container names.