Skip to content
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

[bug] unable to modify files in the store section #1013

Closed
oeiber opened this issue Apr 7, 2021 · 11 comments
Closed

[bug] unable to modify files in the store section #1013

oeiber opened this issue Apr 7, 2021 · 11 comments
Assignees
Labels
bug Something isn't working

Comments

@oeiber
Copy link

oeiber commented Apr 7, 2021

I'm using zwavejs2mqtt from docker registry, running on my pi4.
the container runs with default settings (http on port 8091) and is proxied using nginx.
when i publish zwavejs2mqtt to the root folder (https://domain.tld/) it works fine. But when publishing to a subfolder (e.g. https://domain.tld/zwave/) i'm unable to access files in the store section in the frontend.
X-External-Path header is set correctly as descriped in the manual. when i try to modify a file i can see the following error ishown in the webinterface:
"Request failed with status code 404"
at the same time docker logs the following error:
Error: Not Found at /usr/src/app/app.js:979:15 at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/usr/src/app/node_modules/express/lib/router/index.js:317:13) at /usr/src/app/node_modules/express/lib/router/index.js:284:7 at Function.process_params (/usr/src/app/node_modules/express/lib/router/index.js:335:12) at next (/usr/src/app/node_modules/express/lib/router/index.js:275:10) at /usr/src/app/node_modules/express-session/index.js:502:7 at readCallback (/usr/src/app/node_modules/session-file-store/lib/session-file-helpers.js:193:20) at /usr/src/app/node_modules/graceful-fs/graceful-fs.js:123:16 at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:75:3)

btw this behavior can also be reproduced using supervised homeassistant with ingress functionality.

@oeiber oeiber added the bug Something isn't working label Apr 7, 2021
@robertsLando
Copy link
Member

This is a bug with the zwavejs2mqtt addon not here

@oeiber
Copy link
Author

oeiber commented Apr 8, 2021

I don't think so, because this problem also occours using zwavejs2mqtt as standalone container.
Where should I report the bug?

@robertsLando robertsLando reopened this Apr 8, 2021
@robertsLando
Copy link
Member

I don't think so, because this problem also occours using zwavejs2mqtt as standalone container.

I cannot reproduce your issue so. When i edit files I get no error

@oeiber
Copy link
Author

oeiber commented Apr 8, 2021

did you also publish the webinterface to a subdir as well? i‘m using docker image zwavejs/zwavejs2mqtt:latest

@robertsLando
Copy link
Member

robertsLando commented Apr 9, 2021

did you also publish the webinterface to a subdir as well

I don't know what you mean. I simply did this:

mkdir testZ2M
cd testZ2M
mkdir store // places files in store folder from my local project as I don't use docker
docker pull zwavejs/zwavejs2mqtt:latest // to be sure I have latest
docker run --rm -it -p 8091:8091 --device=/dev/ttyACM0 -v $(pwd)/store:/usr/src/app/store zwavejs/zwavejs2mqtt:latest

@oeiber
Copy link
Author

oeiber commented Apr 9, 2021

I don't know what you mean. I simply did this:

The problem only occurs when using zwavejs behind a reverse proxy, in my case nginx:

When I use the root directory of the webserver everything works fine:

 location   / {
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_pass http://zwave:8091;
}

But when is try to map zwavejs webinterface to a subdirectory, I'm unable to edit files in the frontend:

location   /temp/ {
        proxy_set_header X-External-Path /temp;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_pass http://zwave:8091/;
}

As you can see above, I also set the X-External-Path header as described in the manual: https://zwave-js.github.io/zwavejs2mqtt/#/usage/reverse-proxy

@robertsLando
Copy link
Member

The problem only occurs when using zwavejs behind a reverse proxy, in my case nginx:

This is the same problem that occurs with hass z2m addon as I think they also use a reverse proxy. Seems that the reverso proxy tranlastes the path in the url...

On my side I do: https://github.com/zwave-js/zwavejs2mqtt/blob/master/src/apis/ConfigApis.js#L102

The encodeURIComponent tranlsates urls so all special chars are escaped. Seems that the reverse proxy removes the escapes chars and this causes the url to become wrong causing a 404 error.

Maybe this could be a fix:

https://stackoverflow.com/questions/28995818/nginx-proxy-pass-and-url-decoding
https://stackoverflow.com/questions/20496963/avoid-nginx-decoding-query-parameters-on-proxy-pass-equivalent-to-allowencodeds

@oeiber
Copy link
Author

oeiber commented Apr 12, 2021

Thank you! Now it's working.

Here my NGINX config:

location   /temp/ {
        rewrite ^ $request_uri;
        rewrite '^/zwave(/.*)$' $1 break;
        proxy_set_header X-External-Path /temp;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_pass http://zwave:8091$uri;;
}

Maybe the documentation should be updated as well, shouldn't it?

@robertsLando
Copy link
Member

Could you make a PR for docs?

@robertsLando
Copy link
Member

I already updated the docs.

@robertsLando
Copy link
Member

@oeiber Just for info, isn't

proxy_pass http://zwave:8091$uri;

enought? Do you need also:

rewrite ^ $request_uri;
rewrite '^/zwave(/.*)$' $1 break;

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants