aboutsummaryrefslogtreecommitdiff
path: root/viewer
diff options
context:
space:
mode:
authorZero~Informatique2020-09-12 11:29:57 +0200
committerG.Fouet2020-09-14 01:28:41 +0200
commitb530f65cf7bc32eb4bb16cf445950a0b1ab685b4 (patch)
tree29192f28ceb804caddcadaba83e80f9b98a2ee63 /viewer
parent254858f632bbfd4eb45d0315ed39e0a631e64104 (diff)
downloadldgallery-b530f65cf7bc32eb4bb16cf445950a0b1ab685b4.tar.gz
viewer: handle HTTP authentication: DevServer is now able to switch between HTTP proxy and filesystem.
Diffstat (limited to 'viewer')
-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};