瀏覽代碼

fix http relative path in electron

Signed-off-by: nameczz <zizhao.chen@zilliz.com>
nameczz 2 年之前
父節點
當前提交
7f978226af
共有 3 個文件被更改,包括 17 次插入2 次删除
  1. 1 0
      client/public/env-config.js
  2. 3 2
      client/src/http/Axios.ts
  3. 13 0
      server/electron-starter.js

+ 1 - 0
client/public/env-config.js

@@ -1,4 +1,5 @@
 window._env_ = {
   MILVUS_URL: '127.0.0.1:19530',
   HOST_URL: 'http://127.0.0.1:3000',
+  IS_ELECTRON: '{{IS_ELECTRON}}',
 };

+ 3 - 2
client/src/http/Axios.ts

@@ -4,9 +4,10 @@ import { MILVUS_ADDRESS } from '../consts/Localstorage';
 
 // console.log(process.env.NODE_ENV, 'api:', process.env.REACT_APP_BASE_URL);
 // console.log('docker env', (window as any)._env_);
-
+const isElectron =
+  (window as any)._env_ && (window as any)._env_.IS_ELECTRON === 'yes';
 export const url =
-  process.env.NODE_ENV === 'development'
+  process.env.NODE_ENV === 'development' || isElectron
     ? (window as any)._env_ && (window as any)._env_.HOST_URL
     : '';
 

+ 13 - 0
server/electron-starter.js

@@ -1,4 +1,5 @@
 const electron = require('electron');
+const fs = require('fs');
 require('./dist/src/app');
 
 // Module to control application life.
@@ -25,6 +26,18 @@ function createWindow() {
       enableRemoteModule: true,
     },
   });
+
+  // replace IS_ELECTRON  to yes, beacause axios relative url
+  const envConfig = path.join(__dirname, './build/env-config.js');
+  fs.readFile(envConfig, 'utf8', function (err, files) {
+    const result = files.replace(/{{IS_ELECTRON}}/g, 'yes');
+    fs.writeFile(envConfig, result, 'utf8', function (err) {
+      if (err) {
+        console.log(err);
+      }
+    });
+  });
+
   // mainWindow.maximize();
   // mainWindow.show();
   // and load the index.html of the app.