How to set Cors headers on API node?
Hello, Dataiku Team.
I'm trying to send a POST request to an endpoint I created in an API node. However, I get this error:
Access to XMLHttpRequest at 'http://ip_server/public/api/v1/service_time_series_variables/autocorrelation_analysis/run' from origin 'http://localhost:4401' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
So I applied the solution that I read here, but it did not work.
I see that there is another nginx.conf on the CentOs machine where I installed API node (/etc/nginx/nginx.conf). Should I do a change on this file?
Thank you very much!!
Operating system used: CentOs
Answers
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,090 Neuron
Hi. Can you clarify is ip_server your API node? If so how is it running on port 80? What is http://localhost:4401/ ? Where are you calling your API from?
-
rafael_rosado97 Partner, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 61 Partner
ip_server is a machine ip where I installed the api node.
But, now that you mencioned about the port 80, I saw that port is set on etc/nginx/nginx.conf file.
The real port where the api node listen to is on 11200 (set on ./install-support/nginx.conf).
The api node is called from a dashboard, but I do not really know about the code from that side.
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,090 Neuron
What URL do they use when they call the API from your dashboard? You appear to be using the API node in a reverse proxy configuration. Can you confirm that's the case and that you followed the installation steps for such configuration? Also you will need to modify the correct nginx.conf file, so please review your nginx start up command to confirm which config file are you using.
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,090 Neuron
Also saw you can define them here for Designer node in v12.3.2:
Settings => Other => Misc. => Public API CORS headers
https://doc.dataiku.com/dss/latest/release_notes/12.html#security
-
rafael_rosado97 Partner, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 61 Partner
Yes, it is in a reverse proxy configuration.
When I run the "nginx -t" command on terminal it says:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successfulIt is confusing for me, because I don't understand the difference between /etc/nginx/nginx.conf and /install-support/nginx.conf
-
rafael_rosado97 Partner, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 61 Partner
The thing is that I cannot upgrade to v12 right now . Currently, I have v11.
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,090 Neuron
You can have many configuration files, but only one will be used when nginx is started. If I do "ps -ef | grep nginx" on my system I can see nginx and which config file it was started with.
-
rafael_rosado97 Partner, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 61 Partner
It returns two master processes:
From root: /usr/sbin/nginx
From Dataiku: /usr/sbin/nginx -c /opt/dataiku_11-4-3/dataiku/install-support/nginx.conf
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,090 Neuron
So there are two because you have the one running as root on port 80 or port 443 redirecting to the one running as dataiku user on the high port. You can try to modify the /opt/dataiku_11-4-3/dataiku/install-support/nginx.conf config file first and once you have it working you can move to the root one. But you will need to test using the high port on the /opt/dataiku_11-4-3/dataiku/install-support/nginx.conf config file.
-
rafael_rosado97 Partner, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 61 Partner
It works now.
The configuration was ok. The poblem was the CORS headers location on nginx.conf.
The path used on nginx.conf was /public-cors/, so I modified the endpoint url as http://<ip_machine>:11200/public-cors/api/v1/service_time_series_variables/autocorrelation_analysis/run
Thank you very much!!