How to enable CORS header for installed query

Each installed query exposes an API endpoint, but by default, it doesn’t have CORS header.

Is there a way to enable it? Or, is there any nice workaround?

Thank you!

Hi Di,

You may try this command:

gadmin --configure nginx.headers

and put your customized headers in JSON format: [{“key”: “value”}]

For example:

[{“Access-Control-Allow-Origin”: “http://foo.example”}]

And then, you may apply the config with command

gadmin config-apply

and restart related service:

gadmin restart nginx -y

You may also visit for more details: https://www.tigergraph.com/2020/03/11/working-with-tigergraph-rest-api-and-cors-cross-origin-resource-sharing/

Note: some browsers like Chrome will ignore the CORS from localhost. If you run into this issue, you may try to user a non-localhost hostname by deploying it with a domain or non-local-loopback IP.

1 Like

hello, is the answer outdated?. I have 3.0 developer edition and couldnt enter the command gadmin --configure nginx.headers. do we any other solution on 3.0, please suggest.

Thanks,
Senthil

Hi @rskumuru,

welcome to our community!

The answer is valid for version 2.x - in 3.0 the format how to manage config file has changed:
gadmin config entry nginx.ResponseHeaders

After you changed it, confirm with gadmin config apply

You need to restart the nginx service too:
gadmin restart nginx

Best,
Bruno

Thank you @Bruno, it worked as expected.
Regards,
rskumuru