diff --git a/Dockerfile b/Dockerfile index 8dbbfc1..b6be35f 120000 --- a/Dockerfile +++ b/Dockerfile @@ -94,6 +94,8 @@ RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \ && apt-get update \ && apt-get install -y yarn +ENV PREFIX_PATH = "APP" + # build frontend COPY web /src/web RUN cd /src/web \ diff --git a/image/etc/nginx/sites-enabled/default b/image/etc/nginx/sites-enabled/default index 07a8170..718e553 100644 --- a/image/etc/nginx/sites-enabled/default +++ b/image/etc/nginx/sites-enabled/default @@ -13,11 +13,11 @@ server { root /usr/local/lib/web/frontend/; index index.html index.htm; - location ~ ^/api { + location ~ ^/APP/api { try_files $uri @api; } - location = /websockify { + location = /APP/websockify { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; diff --git a/image/usr/local/lib/web/backend/run.py b/image/usr/local/lib/web/backend/run.py index 62f9b79..a9b29a9 100755 --- a/image/usr/local/lib/web/backend/run.py +++ b/image/usr/local/lib/web/backend/run.py @@ -114,6 +114,9 @@ def main(): ) logging.getLogger("werkzeug").setLevel(logging.WARNING) log = logging.getLogger('novnc2') + + app.config["APPLICATION_ROOT"] = os.getenv("PREFIX_PATH") + entrypoint() diff --git a/web/config/index.js b/web/config/index.js index f54a519..f363a2e 100644 --- a/web/config/index.js +++ b/web/config/index.js @@ -5,6 +5,11 @@ const path = require('path') const BACKEND = process.env.BACKEND || 'http://127.0.0.1:6080' +const PREFIX_PATH = process.env.PREFIX_PATH + +const api_key = `${PREFIX_PATH}/api` +const websockify_key = `${PREFIX_PATH}/websockfiy` + module.exports = { dev: { @@ -12,12 +17,12 @@ module.exports = { assetsSubDirectory: 'static', assetsPublicPath: '/', proxyTable: { - '/api': { + [api_key]: { target: BACKEND, changeOrigin: true, secure: false }, - '/websockify': { + [websockify_key]: { target: BACKEND, // logLevel: 'debug', ws: true, diff --git a/web/src/components/Vnc.vue b/web/src/components/Vnc.vue index 873d0c3..12f5042 100644 --- a/web/src/components/Vnc.vue +++ b/web/src/components/Vnc.vue @@ -56,7 +56,7 @@ export default { 'h': h } try { - const response = await this.$http.get('api/state', {params: params}) + const response = await this.$http.get(process.env.PREFIX_PATH + '/api/state', {params: params}) const body = response.data if (body.code !== 200) { this.stateErrorCount += 1 @@ -71,7 +71,7 @@ export default { // adaptive resolution if (!body.data.config.fixedResolution && body.data.config.sizeChangedCount === 0) { - const response = await this.$http.get('api/reset', {params: params}) + const response = await this.$http.get(process.env.PREFIX_PATH + '/api/reset', {params: params}) const body = response.data if (body.code !== 200) { this.stateErrorCount += 1 @@ -136,6 +136,7 @@ export default { // console.trace() console.log(`connecting...`) this.errorMessage = '' + let websockifyPath = process.env.PREFIX_PATH + '/websockify' if (force || this.vncState === 'stopped') { this.vncState = 'connecting' let hostname = window.location.hostname @@ -146,7 +147,7 @@ export default { let url = 'static/vnc.html?' url += 'autoconnect=1&' url += `host=${hostname}&port=${port}&` - url += `path=websockify&title=novnc2&` + url += `path=${websockifyPath}&title=novnc2&` url += `logging=warn` this.$refs.vncFrame.setAttribute('src', url) } diff --git a/web/src/router/index.js b/web/src/router/index.js index ad0edb9..21e095f 100644 --- a/web/src/router/index.js +++ b/web/src/router/index.js @@ -5,6 +5,8 @@ import Vnc from '@/components/Vnc' Vue.use(Router) export default new Router({ + mode: 'history', + base: process.env.PREFIX_PATH, routes: [ { path: '/',