Hi , I'm trying to query the broker api at <http:/...
# troubleshooting
r
Hi , I'm trying to query the broker api at http://localhost:8099/query/sql but i get the following error response : No 'Access-Control-Allow-Origin' header is present on the requested resource. Any help would be much appreciated .
m
Did you setup Auth/ACL? If so, are you passing access tokens?
r
I havent set up either
m
Are you able to access query console via Pinot UI?
r
yes
i can query in the console fine
m
Can you paste exactly how you are using the broker api?
r
var sqlQuery = '{"sql": "select * from salesTable limit 10"} '; const options = { method: "POST", body: sqlQuery, headers: { "Content-Type": "application/json", }, }; fetch("http://localhost:8099/query/sql", options) .then((response) => response.json()) .then((data) => console.log(data));
m
I think the request is not being formed correctly. Here’s the curl way of doing it. Can you compare what your code is doing vs what the curl example shows? https://docs.pinot.apache.org/users/api/querying-pinot-using-standard-sql
r
im getting a response from the api containing the result from the query but also getting the "CORS" error too
Screenshot 2022-07-05 at 19.15.23.png
j
is the broker running on localhost or are you proxying to a broker somewhere?
Access-Control-Alllow-Origin: *
might fix it either way, but isn’t always recommended for a production use case
r
Broker is running on localhost
Where should i put "access-control-allow-origin:* "
@Johan Adami ?
j
in the
headers
part of your request
r
still get the same errors
think it needs to be set on the resource side
but not sure where to put it
j
ya good point. this is strange, i run everything locally often and haven’t had this issue
k
r
i believe browsers implement 'cors' , this issue occurs on both chrome and safari which i use. I have only ran into this problem using pinot. I need to explicitly set on the broker "Access-Control-Alllow-Origin: * " to resolve the issue, but not sure where i can set this field
k
The SO post I referenced talked about a Chrome plugin that does this for you
r
yep i have used the plugin , it leads to a separate error , and doesnt seem like the clean way of fixing the problem i get this issue using javascript to make the request, is there any documentation making requests via js? I have seen for python, go lang etc
k
I don’t know much about CORS, I only had to deal with it once in a previous project. But I don’t think the issue is with using Javascript to make the request…it’s using JavaScript from inside a browser. I think the reason why maybe you’re seeing it with Pinot is that your request is coming from port 3000, but going to port 8099, so it’s considered different origins.
You could file a request to have Pinot set appropriate HTTP headers in the response.
r
yes that would be ideal
how would i go about filing a request ?
m
GitHub issue