From 8957b4ed8b454af899d7cae33a865445ec654e16 Mon Sep 17 00:00:00 2001 From: Evren Ozkan Date: Thu, 11 May 2017 11:55:36 -0400 Subject: [PATCH] Refactor absoluteUrl to allow multiple domains directed to the same server work --- Packages/ohif-core/both/utils/absoluteUrl.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Packages/ohif-core/both/utils/absoluteUrl.js b/Packages/ohif-core/both/utils/absoluteUrl.js index f695e2269..4b1dbdf7e 100644 --- a/Packages/ohif-core/both/utils/absoluteUrl.js +++ b/Packages/ohif-core/both/utils/absoluteUrl.js @@ -1,11 +1,19 @@ import { OHIF } from 'meteor/ohif:core'; -// Return an absolute URL with the given path by supporting the leading "/" +// Return an absolute URL with the page domain using sub path of ROOT_URL +// to let multiple domains directed to the same server work OHIF.utils.absoluteUrl = function(path) { - if (path) { - // Remove the leading "/" - path = path.replace(/^\//, ''); + let absolutePath = '/'; + + const absoluteUrl = Meteor.absoluteUrl(); + const absoluteUrlParts = absoluteUrl.split('/'); + + if (absoluteUrlParts.length > 4) { + const rootUrlPrefixIndex = absoluteUrl.indexOf(absoluteUrlParts[3]); + absolutePath += absoluteUrl.substring(rootUrlPrefixIndex) + path; + } else { + absolutePath += path; } - return Meteor.absoluteUrl(path); + return absolutePath.replace(/\/\/+/g, '/'); }; \ No newline at end of file