diff options
author | Zero~Informatique | 2020-09-12 11:29:57 +0200 |
---|---|---|
committer | G.Fouet | 2020-09-14 01:28:41 +0200 |
commit | b530f65cf7bc32eb4bb16cf445950a0b1ab685b4 (patch) | |
tree | 29192f28ceb804caddcadaba83e80f9b98a2ee63 | |
parent | 254858f632bbfd4eb45d0315ed39e0a631e64104 (diff) | |
download | ldgallery-b530f65cf7bc32eb4bb16cf445950a0b1ab685b4.tar.gz |
viewer: handle HTTP authentication: DevServer is now able to switch between HTTP proxy and filesystem.
-rw-r--r-- | viewer/vue.config.js | 40 |
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 | */ | ||
25 | const dev_ready = Boolean(process.env.VUE_APP_DEVSERVER_CONFIG_PATH); | ||
26 | const dev_isproxy = dev_ready && Boolean(process.env.VUE_APP_DEVSERVER_CONFIG_PATH.match(/^https?:\/\//i)); | ||
27 | const dev_localpath = `^/${process.env.VUE_APP_DATA_URL}`; | ||
28 | const dev_proxyconfig = { | ||
29 | [dev_localpath]: { | ||
30 | target: process.env.VUE_APP_DEVSERVER_CONFIG_PATH, | ||
31 | pathRewrite: { [dev_localpath]: "" }, | ||
32 | }, | ||
33 | }; | ||
34 | const 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 | |||
20 | module.exports = { | 47 | module.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 | }; |