From b530f65cf7bc32eb4bb16cf445950a0b1ab685b4 Mon Sep 17 00:00:00 2001
From: Zero~Informatique
Date: Sat, 12 Sep 2020 11:29:57 +0200
Subject: viewer: handle HTTP authentication: DevServer is now able to switch
between HTTP proxy and filesystem.
---
viewer/vue.config.js | 40 +++++++++++++++++++++++++++++-----------
1 file 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 @@
-- along with this program. If not, see .
*/
+/*
+-- Create a file .env.development.local in the project to customize your DevServer
+-- VUE_APP_DEVSERVER_CONFIG_PATH= will use the dev_proxyconfig
+-- VUE_APP_DEVSERVER_CONFIG_PATH= will use the dev_fsconfig
+*/
+const dev_ready = Boolean(process.env.VUE_APP_DEVSERVER_CONFIG_PATH);
+const dev_isproxy = dev_ready && Boolean(process.env.VUE_APP_DEVSERVER_CONFIG_PATH.match(/^https?:\/\//i));
+const dev_localpath = `^/${process.env.VUE_APP_DATA_URL}`;
+const dev_proxyconfig = {
+ [dev_localpath]: {
+ target: process.env.VUE_APP_DEVSERVER_CONFIG_PATH,
+ pathRewrite: { [dev_localpath]: "" },
+ },
+};
+const dev_fsconfig = (app, server, compiler) => {
+ app.get(`${dev_localpath}*`, (req, res) => {
+ const fs = require("fs");
+ const url = req.url.slice(process.env.VUE_APP_DATA_URL.length);
+ const paramIdx = url.indexOf("?");
+ const filepath = paramIdx < 0 ? url : url.substring(0, paramIdx);
+ const fullpath = `${process.env.VUE_APP_DEVSERVER_CONFIG_PATH}${decodeURIComponent(filepath)}`;
+ const file = fs.readFileSync(fullpath);
+ res.end(file);
+ });
+};
+// =================
+
module.exports = {
publicPath: "./",
pluginOptions: {
@@ -37,16 +64,7 @@ module.exports = {
devServer: {
port: process.env.VUE_APP_DEVSERVER_PORT,
serveIndex: true,
- before: (app, server, compiler) => {
- app.get(`/${process.env.VUE_APP_DATA_URL}*`, (req, res) => {
- const fs = require("fs");
- const url = req.url.slice(process.env.VUE_APP_DATA_URL.length);
- const paramIdx = url.indexOf("?");
- const filepath = paramIdx < 0 ? url : url.substring(0, paramIdx);
- const fullpath = `${process.env.VUE_APP_DEVSERVER_CONFIG_PATH}${decodeURIComponent(filepath)}`;
- const file = fs.readFileSync(fullpath);
- res.end(file);
- });
- },
+ proxy: dev_ready && dev_isproxy ? dev_proxyconfig : undefined,
+ before: dev_ready && !dev_isproxy ? dev_fsconfig : undefined,
},
};
--
cgit v1.2.3