Pārlūkot izejas kodu

refactoring: minor changes to #8122

Torkel Ödegaard 8 gadi atpakaļ
vecāks
revīzija
b77991f69b
1 mainītis faili ar 24 papildinājumiem un 19 dzēšanām
  1. 24 19
      public/app/core/services/backend_srv.ts

+ 24 - 19
public/app/core/services/backend_srv.ts

@@ -63,17 +63,20 @@ export class BackendSrv {
 
 
   request(options) {
   request(options) {
     options.retry = options.retry || 0;
     options.retry = options.retry || 0;
-    var requestIsLocal = options.url.indexOf('/') === 0;
+    var requestIsLocal = !options.url.match(/^http/);
     var firstAttempt = options.retry === 0;
     var firstAttempt = options.retry === 0;
 
 
-    if (!options.url.match('https?://') && this.contextSrv && this.contextSrv.user && this.contextSrv.user.orgId) {
-      options.headers = options.headers || {};
-      options.headers['X-Grafana-Org-Id'] = this.contextSrv.user.orgId;
-    }
 
 
-    if (requestIsLocal && !options.hasSubUrl) {
-      options.url = config.appSubUrl + options.url;
-      options.hasSubUrl = true;
+    if (requestIsLocal) {
+      if (this.contextSrv.user && this.contextSrv.user.orgId) {
+        options.headers = options.headers || {};
+        options.headers['X-Grafana-Org-Id'] = this.contextSrv.user.orgId;
+      }
+
+      if (!options.hasSubUrl) {
+        options.url = config.appSubUrl + options.url;
+        options.hasSubUrl = true;
+      }
     }
     }
 
 
     return this.$http(options).then(results => {
     return this.$http(options).then(results => {
@@ -130,21 +133,23 @@ export class BackendSrv {
       this.addCanceler(requestId, canceler);
       this.addCanceler(requestId, canceler);
     }
     }
 
 
-    var requestIsLocal = options.url.indexOf('/') === 0;
+    var requestIsLocal = !options.url.match(/^http/);
     var firstAttempt = options.retry === 0;
     var firstAttempt = options.retry === 0;
 
 
-    if (!options.url.match('https?://') && this.contextSrv && this.contextSrv.user && this.contextSrv.user.orgId) {
-      options.headers = options.headers || {};
-      options.headers['X-Grafana-Org-Id'] = this.contextSrv.user.orgId;
-    }
+    if (requestIsLocal) {
+      if (this.contextSrv.user && this.contextSrv.user.orgId) {
+        options.headers = options.headers || {};
+        options.headers['X-Grafana-Org-Id'] = this.contextSrv.user.orgId;
+      }
 
 
-    if (requestIsLocal && !options.hasSubUrl && options.retry === 0) {
-      options.url = config.appSubUrl + options.url;
-    }
+      if (!options.hasSubUrl && options.retry === 0) {
+        options.url = config.appSubUrl + options.url;
+      }
 
 
-    if (requestIsLocal && options.headers && options.headers.Authorization) {
-      options.headers['X-DS-Authorization'] = options.headers.Authorization;
-      delete options.headers.Authorization;
+      if (options.headers && options.headers.Authorization) {
+        options.headers['X-DS-Authorization'] = options.headers.Authorization;
+        delete options.headers.Authorization;
+      }
     }
     }
 
 
     return this.$http(options).catch(err => {
     return this.$http(options).catch(err => {