浏览代码

HUE-8856 [frontend] Add support for any base url in the web workers

Johan Ahlen 6 年之前
父节点
当前提交
524631b492

+ 5 - 1
desktop/core/src/desktop/js/sql/sqlLocationWebWorker.js

@@ -14,7 +14,6 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-import 'utils/workerPublicPath';
 import '@babel/polyfill';
 import sqlParserRepository from 'parse/sql/sqlParserRepository';
 
@@ -42,8 +41,13 @@ const handleStatement = (statement, locations, autocompleteParser, active) => {
 };
 
 let throttle = -1;
+let baseUrlSet = false;
 
 const onMessage = msg => {
+  if (!baseUrlSet) {
+    __webpack_public_path__ = (msg.data.hueBaseUrl || '') + '/dynamic_bundle/workers/';
+    baseUrlSet = true;
+  }
   if (msg.data.ping) {
     postMessage({ ping: true });
     return;

+ 5 - 1
desktop/core/src/desktop/js/sql/sqlSyntaxWebWorker.js

@@ -14,7 +14,6 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-import 'utils/workerPublicPath';
 import '@babel/polyfill';
 import sqlParserRepository from 'parse/sql/sqlParserRepository';
 
@@ -37,8 +36,13 @@ const toAbsoluteLocation = (statementLocation, nestedLocation) => {
 };
 
 let throttle = -1;
+let baseUrlSet = false;
 
 const onMessage = msg => {
+  if (!baseUrlSet) {
+    __webpack_public_path__ = (msg.data.hueBaseUrl || '') + '/dynamic_bundle/workers/';
+    baseUrlSet = true;
+  }
   if (msg.data.ping) {
     postMessage({ ping: true });
     return;

+ 2 - 1
desktop/core/src/desktop/js/sql/sqlWorkerHandler.js

@@ -64,9 +64,10 @@ export default {
     if (!window.IS_EMBEDDED && !registered && window.Worker) {
       // It can take a while before the worker is active
       const whenWorkerIsReady = function(worker, message) {
+        message.hueBaseUrl = window.HUE_BASE_URL;
         if (!worker.isReady) {
           window.clearTimeout(worker.pingTimeout);
-          worker.postMessage({ ping: true });
+          worker.postMessage({ ping: true, hueBaseUrl: message.hueBaseUrl });
           worker.pingTimeout = window.setTimeout(() => {
             whenWorkerIsReady(worker, message);
           }, 500);

+ 0 - 1
desktop/core/src/desktop/js/utils/workerPublicPath.js

@@ -1 +0,0 @@
-__webpack_public_path__ = (WorkerGlobalScope.HUE_BASE_URL || '') + '/dynamic_bundle/workers/';

+ 0 - 3
desktop/core/src/desktop/templates/ace_sql_location_worker.mako

@@ -18,9 +18,6 @@
   from webpack_loader import utils
 %>
 
-WorkerGlobalScope.KNOX_BASE_PATH_HUE = '/KNOX_BASE_PATH_HUE';
-WorkerGlobalScope.HUE_BASE_URL = WorkerGlobalScope.KNOX_BASE_PATH_HUE.indexOf('KNOX_BASE_PATH_HUE') < 0 ? WorkerGlobalScope.KNOX_BASE_PATH_HUE : '';
-
 % for js_file in utils.get_files('sqlLocationWebWorker', config='WORKERS'):
   importScripts('${ js_file.get('url') }');
 % endfor

+ 0 - 3
desktop/core/src/desktop/templates/ace_sql_syntax_worker.mako

@@ -18,9 +18,6 @@
   from webpack_loader import utils
 %>
 
-WorkerGlobalScope.KNOX_BASE_PATH_HUE = '/KNOX_BASE_PATH_HUE';
-WorkerGlobalScope.HUE_BASE_URL = WorkerGlobalScope.KNOX_BASE_PATH_HUE.indexOf('KNOX_BASE_PATH_HUE') < 0 ? WorkerGlobalScope.KNOX_BASE_PATH_HUE : '';
-
 % for js_file in utils.get_files('sqlSyntaxWebWorker', config='WORKERS'):
   importScripts('${ js_file.get('url') }');
 % endfor