diff --git a/config/environments/development.js.example b/config/environments/development.js.example index d6bfba7f..edc45308 100644 --- a/config/environments/development.js.example +++ b/config/environments/development.js.example @@ -133,26 +133,6 @@ var config = { statusInterval: 5000 // time, in ms, between each status report is emitted from the pool, status is sent to statsd } } - ,sqlapi: { - protocol: 'http', - // If "host" is given, it will be used - // to connect to the SQL-API without a - // DNS lookup - host: '127.0.0.1', - port: 8080, - // The "domain" part will be appended to - // the cartodb username and passed to - // SQL-API requests in the Host HTTP header - domain: 'localhost.lan', - version: 'v1', - // Maximum lenght of SQL query for GET - // requests. Longer queries will be sent - // using POST. Defaults to 2048 - max_get_sql_length: 2048, - // Maximum time to wait for a response, - // in milliseconds. Defaults to 100. - timeout: 100 - } ,varnish: { host: 'localhost', port: 6082, // the por for the telnet interface where varnish is listening to diff --git a/config/environments/production.js.example b/config/environments/production.js.example index e58aea66..fecc6e9a 100644 --- a/config/environments/production.js.example +++ b/config/environments/production.js.example @@ -127,26 +127,6 @@ var config = { statusInterval: 5000 // time, in ms, between each status report is emitted from the pool, status is sent to statsd } } - ,sqlapi: { - protocol: 'https', - // If "host" is given, it will be used - // to connect to the SQL-API without a - // DNS lookup - //host: '127.0.0.1', - port: 8080, - // The "domain" part will be appended to - // the cartodb username and passed to - // SQL-API requests in the Host HTTP header - domain: 'cartodb.com', - version: 'v2', - // Maximum lenght of SQL query for GET - // requests. Longer queries will be sent - // using POST. Defaults to 2048 - max_get_sql_length: 2048, - // Maximum time to wait for a response, - // in milliseconds. Defaults to 100. - timeout: 100 - } ,varnish: { host: 'localhost', port: 6082, // the por for the telnet interface where varnish is listening to diff --git a/config/environments/staging.js.example b/config/environments/staging.js.example index 8f4b0941..3f125e55 100644 --- a/config/environments/staging.js.example +++ b/config/environments/staging.js.example @@ -127,26 +127,6 @@ var config = { statusInterval: 5000 // time, in ms, between each status report is emitted from the pool, status is sent to statsd } } - ,sqlapi: { - protocol: 'https', - // If "host" is given, it will be used - // to connect to the SQL-API without a - // DNS lookup - //host: '127.0.0.1', - port: 8080, - // The "domain" part will be appended to - // the cartodb username and passed to - // SQL-API requests in the Host HTTP header - domain: 'cartodb.com', - version: 'v2', - // Maximum lenght of SQL query for GET - // requests. Longer queries will be sent - // using POST. Defaults to 2048 - max_get_sql_length: 2048, - // Maximum time to wait for a response, - // in milliseconds. Defaults to 100. - timeout: 100 - } ,varnish: { host: 'localhost', port: 6082, // the por for the telnet interface where varnish is listening to diff --git a/config/environments/test.js.example b/config/environments/test.js.example index 64c40ffd..ca209751 100644 --- a/config/environments/test.js.example +++ b/config/environments/test.js.example @@ -129,28 +129,6 @@ var config = { statusInterval: 5000 // time, in ms, between each status report is emitted from the pool, status is sent to statsd } } - ,sqlapi: { - protocol: 'http', - // If "host" is given, it will be used - // to connect to the SQL-API without a - // DNS lookup - host: '127.0.0.1', - port: 1080, - // The "domain" part will be appended to - // the cartodb username and passed to - // SQL-API requests in the Host HTTP header - domain: 'donot_look_this_up', - // This port will be used by "make check" for testing purposes - // It must be available - version: 'v1', - // Maximum lenght of SQL query for GET - // requests. Longer queries will be sent - // using POST. Defaults to 2048 - max_get_sql_length: 2048, - // Maximum time to wait for a response, - // in milliseconds. Defaults to 100. - timeout: 100 - } ,varnish: { host: '', port: null, // the por for the telnet interface where varnish is listening to diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index 6bf0c32b..da3e6156 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -7,15 +7,6 @@ var LZMA = require('lzma').LZMA; var TemplateMaps = require('./template_maps.js'); var MapConfigNamedLayersAdapter = require('./models/mapconfig_named_layers_adapter'); -// This is for backward compatibility with 1.3.3 -if ( _.isUndefined(global.environment.sqlapi.domain) ) { - // Only use "host" as "domain" if it contains alphanumeric characters - var host = global.environment.sqlapi.host; - if ( host && host.match(/[a-zA-Z]/) ) { - global.environment.sqlapi.domain = host; - } -} - // Whitelist query parameters and attach format var REQUEST_QUERY_PARAMS_WHITELIST = [ 'user', diff --git a/lib/cartodb/sql/sql_api.js b/lib/cartodb/sql/sql_api.js deleted file mode 100644 index 32885e57..00000000 --- a/lib/cartodb/sql/sql_api.js +++ /dev/null @@ -1,66 +0,0 @@ -var _ = require('underscore'), - request = require('request'); - -module.exports.query = function (username, api_key, sql, callback) { - var api = global.environment.sqlapi; - - // build up api string - var sqlapihostname = username; - if ( api.domain ) sqlapihostname += '.' + api.domain; - - var sqlapi = api.protocol + '://'; - if ( api.host && api.host != api.domain ) sqlapi += api.host; - else sqlapi += sqlapihostname; - sqlapi += ':' + api.port + '/api/' + api.version + '/sql'; - - var qs = { q: sql }; - - // add api_key if given - if (_.isString(api_key) && api_key !== '') { qs.api_key = api_key; } - - // call sql api - // - // NOTE: using POST to avoid size limits: - // See http://github.com/CartoDB/Windshaft-cartodb/issues/111 - // - // NOTE: uses "host" header to allow IP based specification - // of sqlapi address (and avoid a DNS lookup) - // - // NOTE: allows for keeping up to "maxConnections" concurrent - // sockets opened per SQL-API host. - // See http://nodejs.org/api/http.html#http_agent_maxsockets - // - var maxSockets = global.environment.maxConnections || 128; - var maxGetLen = api.max_get_sql_length || 2048; - var maxSQLTime = api.timeout || 100; // 1/10 of a second by default - var reqSpec = { - url:sqlapi, - json:true, - headers:{host: sqlapihostname}, - // http://nodejs.org/api/http.html#http_agent_maxsockets - pool:{maxSockets:maxSockets}, - // timeout in milliseconds - timeout:maxSQLTime - }; - if ( sql.length > maxGetLen ) { - reqSpec.method = 'POST'; - reqSpec.body = qs; - } else { - reqSpec.method = 'GET'; - reqSpec.qs = qs; - } - request(reqSpec, function(err, res, body) { - if (err){ - console.log('ERROR connecting to SQL API on ' + sqlapi + ': ' + err); - callback(err); - return; - } - if (res.statusCode != 200) { - var msg = res.body.error ? res.body.error : res.body; - callback(new Error(msg)); - console.log('unexpected response status (' + res.statusCode + ') for sql query: ' + sql + ': ' + msg); - return; - } - callback(null, body.rows); - }); -};