title: Traefik 2 & Docker - CORS error on ElasticSearch api
body: <p>I use Docker &amp; Traefik to manage a ReactJS app calling an ElasticSearch API.</p>
  <p>Here is my elasticsearch.yml config :</p>
  <pre><code>cluster.name: &quot;docker-cluster&quot;
  network.host: 0.0.0.0
  http.cors.enabled : true
  http.cors.allow-origin: &quot;*&quot;
  http.cors.allow-methods: OPTIONS, HEAD, GET, POST, PUT, DELETE
  http.cors.allow-headers: X-Requested-With,X-Auth-Token,Content-Type,Content-Length
  http.cors.allow-credentials: true
  xpack.security.enabled: true
  xpack.security.authc.api_key.enabled: true
  </code></pre>
  <p>And here the entry in docker-compose for my Elasticsearch service :</p>
  <pre><code>elasticsearch:
      image: docker.elastic.co/elasticsearch/elasticsearch:7.12.0
      restart: always
      volumes:
        - ${DATA_FOLDER_ELASTICHSEARCH}:/usr/share/elasticsearch/data
        - ./infra/elasticsearch/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      environment:
        - discovery.type=single-node      
      labels:
        - &quot;traefik.enable=true&quot;
        - &quot;traefik.http.routers.elasticsearch.rule=Host(`myElastic.domain.com`)&quot;
        - &quot;traefik.http.routers.elasticsearch.entrypoints=websecure&quot;
        - &quot;traefik.http.routers.elasticsearch.middlewares=testHeader&quot;   
        - &quot;traefik.http.middlewares.testHeader.headers.accesscontrolallowmethods=GET,OPTIONS,POST&quot;
        - &quot;traefik.http.middlewares.testHeader.headers.accesscontrolalloworiginlist=*&quot;
        - &quot;traefik.http.middlewares.testHeader.headers.accesscontrolmaxage=100&quot;
        - &quot;traefik.http.middlewares.testHeader.headers.addvaryheader=true&quot;
      networks:
        - myNetwork
  </code></pre>
  <p>If I call my ElasticSearch API (like a simple POST on <code>/myIndex/_search</code> using Postman for example, I have my response headers :</p>
  <pre><code>Access-Control-Allow-Origin : *
  Vary : Origin
  </code></pre>
  <p>But I still have the CORS issue on my React app using fetch (for now I use directly the ElasticSearch API from my react).</p>
  <p>Do I need to change anything from the fetch api ?</p>
  <p><strong>EDIT</strong></p>
  <p>Looking at <a href="https://stackoverflow.com/questions/19743396/cors-cannot-use-wildcard-in-access-control-allow-origin-when-credentials-flag-i">CORS: Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true</a>, it seems I can't use <code>*</code> to define my allowed domains, so I put :</p>
  <pre><code>- &quot;traefik.http.middlewares.testHeader.headers.accesscontrolalloworiginlist=https://reactApp.domain.com&quot;
  </code></pre>
  <p>But no success ... in my Chrome console, I have this message :</p>
  <pre><code>preflight wildcard origin not allowed
  </code></pre>