using sql_api_template
This commit is contained in:
parent
a61976727c
commit
a822c369c7
@ -325,20 +325,7 @@ var Profiler = require('../profiler');
|
|||||||
|
|
||||||
url: function(subhost) {
|
url: function(subhost) {
|
||||||
var opts = this.options;
|
var opts = this.options;
|
||||||
var protocol = opts.sql_api_protocol || 'http';
|
return opts.sql_api_template.replace('{user}', (opts.user_name || opts.user)).replace('{s}', subhost) + "/api/v1/sql";
|
||||||
if (!this.options.cdn_url) {
|
|
||||||
return this._host();
|
|
||||||
}
|
|
||||||
var h = protocol+ "://";
|
|
||||||
if (subhost) {
|
|
||||||
h += subhost + ".";
|
|
||||||
}
|
|
||||||
var cdn_host = opts.cdn_url;
|
|
||||||
if(!cdn_host.http && !cdn_host.https) {
|
|
||||||
throw new Error("cdn_host should contain http and/or https entries");
|
|
||||||
}
|
|
||||||
h += cdn_host[protocol] + "/" + (opts.user_name || opts.user) + '/api/v2/sql';
|
|
||||||
return h;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_hash: function(str) {
|
_hash: function(str) {
|
||||||
@ -371,18 +358,8 @@ var Profiler = require('../profiler');
|
|||||||
// execute actual query
|
// execute actual query
|
||||||
sql: function(sql, callback, options) {
|
sql: function(sql, callback, options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
var subdomains = this.options.subdomains || '0123';
|
var subdomains = this.options.subdomains || 'abcd';
|
||||||
if(this.isHttps()) {
|
url = this.url(subdomains[Math.abs(this._hash(sql))%subdomains.length]);
|
||||||
subdomains = [null]; // no subdomain
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var url;
|
|
||||||
if (options.no_cdn) {
|
|
||||||
url = this._host();
|
|
||||||
} else {
|
|
||||||
url = this.url(subdomains[Math.abs(this._hash(sql))%subdomains.length]);
|
|
||||||
}
|
|
||||||
var extra = this._extraParams();
|
var extra = this._extraParams();
|
||||||
torque.net.get( url + "?q=" + encodeURIComponent(sql) + (extra ? "&" + extra: ''), function (data) {
|
torque.net.get( url + "?q=" + encodeURIComponent(sql) + (extra ? "&" + extra: ''), function (data) {
|
||||||
if(options.parseJSON) {
|
if(options.parseJSON) {
|
||||||
|
Loading…
Reference in New Issue
Block a user