How to get the configuration for the React app from "CONSUL"

869 views Asked by At

I was using .env files, to read all the configurations, now I want to read all my configurations from the consul at runtime.

const consulServer = consul({
    host: 'my-host',
    port:123,
})
consulServer.kv.get('url', (err: any, response: { Value: any }) => {
    if (!err && response.Value) {
        console.log(response.Value)
    } else {
        console.log('Failed to load consul configuration', err)
    }
})

I am running CONSUl and react app on my local in different ports, but while reading the consul I am getting cors error

any help here much appreciated

1

There are 1 answers

0
Blake Covarrubias On

You can configure server-side HTTP headers for CORS under Consul's http_config.response_headers configuration option.

HCL

http_config {
  response_headers {
    Access-Control-Allow-Origin = "*"
  }
}

JSON

{
  "http_config": {
    "response_headers": {
      "Access-Control-Allow-Origin": "*"
    }
  }
}