Stack Exchange Network
Stack Exchange network consists of 183 Q&A communities including
Stack Overflow
, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this community
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I have successfully installed CartoDB in Ubuntu 14.04 LTS and uploaded a point geometry dataset. I have created a HTML/JS application to access the layers from the local cartodb and visualize in the leaflet client application using cartodb.createLayer.
I need to display a chart by using the data from the uploaded layer. When I try using CartoDB SQL API, I get the CORS error. The details are below.
Can you let me know whether we need to include any configuration for CORS in local cartoDB?
Code:
$.getJSON('http://development.localhost.lan:3000/api/v2/sql?q=SELECT * FROM tablename & api_key = 1a77a491a96dff1c380fc869498587db105c5b65', function(data) {
console.log(data);
$.each(data.rows, function(key, val) {
// do something!
Error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading
the remote resource at
http://development.localhost.lan:3000/api/v2/sql?q=SELECT%20*%20FROM%20%22qgis_view_standard_all_permits_processed_current%22%20&%20api_key%20=%201a77a491a96dff1c380fc869498587db105c5b65.
(Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
The problem got resolved. The actual error was 2 things as described below.
Error 1 : The URL for accessing SQL API was wrong. The Correct URL is "http://development.localhost.lan:8080/api/v1/sql"
Error 2 : The access to the dataset was private. When I change to "public" I could access the query result.
But I am not sure why the private dataset is not accessible even though I give api_key along with the query
The SQL API works for private dataset too when the api_key is sent along with the URL without any spaces in the URL as below.
http://development.localhost.lan:8080/api/v2/sql?q=SELECT * FROM tablename&api_key=1a77a491a96dff1c380fc869498587db105c5b65
Another option to circumvent CORS errors in a local installation is to use domainless URLs like http://local-installation/user/username/: https://cartodb.readthedocs.io/en/latest/configuration.html#domainless-urls
If the cartoDB and the webserver can share the same hostname and port.
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.