Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jerome83136 opened this issue Sep 10, 2022 · 9 comments
Closed

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

jerome83136 opened this issue Sep 10, 2022 · 9 comments
Assignees
Labels
question Further information is requested

Comments

@jerome83136
Copy link

jerome83136 commented Sep 10, 2022

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

@jerome83136 jerome83136 added the question Further information is requested label Sep 10, 2022
@robertsLando
Copy link
Member

robertsLando commented Sep 12, 2022

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

@jerome83136
Copy link
Author

jerome83136 commented Sep 12, 2022 via email

@jerome83136
Copy link
Author

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
Copy link
Member

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

X-External-Path /zwave;

@robertsLando
Copy link
Member

robertsLando commented Sep 12, 2022

Just commited a change to add BASE_PATH env var

robertsLando added a commit that referenced this issue Sep 12, 2022
@jerome83136
Copy link
Author

jerome83136 commented Sep 15, 2022

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
Copy link

tjmv commented Sep 15, 2022

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
Copy link
Author

jerome83136 commented Sep 16, 2022 via email

@jerome83136
Copy link
Author

it worked with the @tjmv solution
Thanks !
Regards

@zwave-js zwave-js locked and limited conversation to collaborators Sep 19, 2022
@robertsLando robertsLando converted this issue into discussion #2655 Sep 19, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants