zwave-js / zwave-js-ui

Full featured Z-Wave Control Panel UI and MQTT gateway. Built using Nodejs, and Vue/Vuetify
https://zwave-js.github.io/zwave-js-ui
MIT License
959 stars 205 forks source link

Unable to set "base" URI path for use behing a reverse proxy #2637

Closed jerome83136 closed 2 years ago

jerome83136 commented 2 years ago

Hello,

I just pulled the latest docker image and I'm unable to configure the "base path" of the application in order to use it behind a reverse proxy.

I modified this file: config/app.js and changed this: exports.base = '/zwave/';

Then restarted the docker.

Then trying to access the app: http://[IP]:8091/zwave

I get these URI generated on these HTTP status code on my browser:

http://[IP]:8091/zwave --> HTTP/200
http://[IP]:8091/zwave/static/css/app.e7f63f8bf06c7dd2f2ba.css --> HTTP/404

It seems the config works because URIs are generated with "/zwave"; but static elements are not reachable on the new path. Did I miss something ?

When manually changing the static URI; it works: http://[IP]:8091/static/css/app.e7f63f8bf06c7dd2f2ba.css --> HTTP/200

I was also unable to apply the documented procedure here: https://zwave-js.github.io/zwavejs2mqtt/#/usage/reverse-proxy?id=using-the-configuration

Thank you for your help Best regards

robertsLando commented 2 years ago

Did you also tried the http header way? what's your reverse proxy configuration?

jerome83136 commented 2 years ago

Hello, No I didn't. I'm using Traefik as a reverse proxy so I have to figure out how to implement this method on it.

Do you think I should give up with the "path" method?

(I think the possibility to set the path thought a docker environment variable could help a lot of people implementing this easier 😉)

Le lun. 12 sept. 2022 à 09:44, Daniel Lando @.***> a écrit :

Did you also tried the http header way?

— Reply to this email directly, view it on GitHub https://github.com/zwave-js/zwavejs2mqtt/issues/2637#issuecomment-1243342027, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJEQYH6TQ77P6DHAOVHZALV53NMFANCNFSM6AAAAAAQJNAOTI . You are receiving this because you authored the thread.Message ID: @.***>

jerome83136 commented 2 years ago

Here is my Traefik configuration (reverse proxy)

accessLog: {}
log:
  level: INFO
providers:
  file:
    filename: /etc/traefik/traefik.yml
    watch: true
api:
  dashboard: true
  insecure: true
entryPoints:
  web:
    address: ":80"
http:
  routers:
    api:
      rule: Host("domotique.maison.lan")
      service: api@internal
    ##zwave2mqtt
    zwave2mqtt:
      rule: Host("domotique.maison.lan") && PathPrefix("/zwave/")
      service: zwave2mqtt
      priority: 1000
  services:
   zwave2mqtt:
    loadBalancer:
     servers:
      - url: "http://192.168.1.253:8091"

But I don't think it will be usefull here as the path is not working by connecting directly to the zwave2mqtt docker instance (http://[IP]:8091/zwave)

I think the static pages are not inheriting the "path" configuration. What do you think ?

Best regards

robertsLando commented 2 years ago

Could you set custom headers? You should add this header:

X-External-Path /zwave;
robertsLando commented 2 years ago

Just commited a change to add BASE_PATH env var

jerome83136 commented 2 years ago

Hello,

Just tried the header way with Traefik; here is the config:

http:
  routers:
    ##zwave2mqtt
    zwave2mqtt:
      rule: Host("domotique.maison.lan") && PathPrefix("/zwave/")
      service: zwave2mqtt
      priority: 1000
      middlewares:
        - zwave2mqtt
  middlewares:
    zwave2mqtt:
      headers:
        customRequestHeaders:
          X-External-Path: "/zwave"
        customResponseHeaders:
          X-External-Path: "/zwave"
  services:
   zwave2mqtt:
    loadBalancer:
     servers:
      - url: "http://ZWAVE2MQTTIP:8091"

Sadly, it still doesn't work.

The "X-External-Path" header is set with the value "/zwave" and when reaching zwavemqtt trought the reverse proxy; the "root" page is accesible with the "/zwave" URI The static pages inherited the "/zwave" URI; but they are still unreachable (404)

This is the same behaviour than with the "path" config option.

Will try with the "BASE_PATH" environment variable when it is released.

Best regards

tjmv commented 2 years ago

I encountered the same issues when I set up the service today and happened to see the commit mentioning this issue. The BASE_PATH environment variable alone is not enough and has the same effect as the header: This adds the prefix, but the server is not aware of it and expects everything to be served from the root. However, you can work around it by first adding the path in the application and then strip it in the proxy.

Using Traefik, you need two middlewares or one and the BASE_PATH variable to get it working right now:

zwave2mqtt-inject-basepath:
  headers:
    customRequestHeaders:
      X-External-Path: "/zwave/"
zwave2mqtt-strip-basepath:
  stripprefix:
    prefixes: "/zwave"
jerome83136 commented 2 years ago

Oh, great tip Will try it asap Thank you !

Le jeu. 15 sept. 2022 à 20:04, tjmv @.***> a écrit :

I encountered the same issues when I set up the service today and happened to see the commit mentioning this issue. The BASE_PATH environment variable alone is not enough and has the same effect as the header: This adds the prefix, but the server is not aware of it and expects everything to be served from the root. However, you can work around it by first adding the path in the application and then strip it in the proxy.

Using Traefik, you need two middlewares or one and the BASE_PATH variable to get it working right now:

zwave2mqtt-inject-basepath: headers: customRequestHeaders: X-External-Path: "/zwave/" zwave2mqtt-strip-basepath: stripprefix: prefixes: "/zwave"

— Reply to this email directly, view it on GitHub https://github.com/zwave-js/zwavejs2mqtt/issues/2637#issuecomment-1248431754, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJEQYHUCLEMN26AO7QE77DV6NQMJANCNFSM6AAAAAAQJNAOTI . You are receiving this because you authored the thread.Message ID: @.***>

jerome83136 commented 2 years ago

it worked with the @tjmv solution Thanks ! Regards