aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--viewer/vue.config.js40
1 files changed, 29 insertions, 11 deletions
diff --git a/viewer/vue.config.js b/viewer/vue.config.js
index 9240964..8649b6d 100644
--- a/viewer/vue.config.js
+++ b/viewer/vue.config.js
@@ -17,6 +17,33 @@
17-- along with this program. If not, see <https://www.gnu.org/licenses/>. 17-- along with this program. If not, see <https://www.gnu.org/licenses/>.
18*/ 18*/
19 19
20/*
21-- Create a file .env.development.local in the project to customize your DevServer
22-- VUE_APP_DEVSERVER_CONFIG_PATH=<http_url> will use the dev_proxyconfig
23-- VUE_APP_DEVSERVER_CONFIG_PATH=<fs_path> will use the dev_fsconfig
24*/
25const dev_ready = Boolean(process.env.VUE_APP_DEVSERVER_CONFIG_PATH);
26const dev_isproxy = dev_ready && Boolean(process.env.VUE_APP_DEVSERVER_CONFIG_PATH.match(/^https?:\/\//i));
27const dev_localpath = `^/${process.env.VUE_APP_DATA_URL}`;
28const dev_proxyconfig = {
29 [dev_localpath]: {
30 target: process.env.VUE_APP_DEVSERVER_CONFIG_PATH,
31 pathRewrite: { [dev_localpath]: "" },
32 },
33};
34const dev_fsconfig = (app, server, compiler) => {
35 app.get(`${dev_localpath}*`, (req, res) => {
36 const fs = require("fs");
37 const url = req.url.slice(process.env.VUE_APP_DATA_URL.length);
38 const paramIdx = url.indexOf("?");
39 const filepath = paramIdx < 0 ? url : url.substring(0, paramIdx);
40 const fullpath = `${process.env.VUE_APP_DEVSERVER_CONFIG_PATH}${decodeURIComponent(filepath)}`;
41 const file = fs.readFileSync(fullpath);
42 res.end(file);
43 });
44};
45// =================
46
20module.exports = { 47module.exports = {
21 publicPath: "./", 48 publicPath: "./",
22 pluginOptions: { 49 pluginOptions: {
@@ -37,16 +64,7 @@ module.exports = {
37 devServer: { 64 devServer: {
38 port: process.env.VUE_APP_DEVSERVER_PORT, 65 port: process.env.VUE_APP_DEVSERVER_PORT,
39 serveIndex: true, 66 serveIndex: true,
40 before: (app, server, compiler) => { 67 proxy: dev_ready && dev_isproxy ? dev_proxyconfig : undefined,
41 app.get(`/${process.env.VUE_APP_DATA_URL}*`, (req, res) => { 68 before: dev_ready && !dev_isproxy ? dev_fsconfig : undefined,
42 const fs = require("fs");
43 const url = req.url.slice(process.env.VUE_APP_DATA_URL.length);
44 const paramIdx = url.indexOf("?");
45 const filepath = paramIdx < 0 ? url : url.substring(0, paramIdx);
46 const fullpath = `${process.env.VUE_APP_DEVSERVER_CONFIG_PATH}${decodeURIComponent(filepath)}`;
47 const file = fs.readFileSync(fullpath);
48 res.end(file);
49 });
50 },
51 }, 69 },
52}; 70};