volkszaehler / mbmd

ModBus Measurement Daemon - simple reading of data from ModBus meters and grid inverters
BSD 3-Clause "New" or "Revised" License
224 stars 81 forks source link

Using mbmd with reverse-proxy #334

Closed twam closed 5 months ago

twam commented 5 months ago

Hey!

I want to use mbmd with a reverse-proxy that maps the mbmd website to https://hostname/mbmd. The website however still tries to reach wss://hostname/ws which isn't working as the correct URL would be wss://hostname/mbmd/ws.

Would it be possible to adapt the URL for such use-cases?

Best regards Tobias

Jennes commented 5 months ago

With this commit included, the web frontend doesn't work anymore when accessed directly with a web browser. The current chrome version then tries to access ws://localhost:80//ws (mind the double '/' in the path section of the URL)

My VueJS and JS knowledge is rather limited, so I wouldn't know how to insert loc.pathname only when it's not empty or not equal to "/" in an elegant way.

andig commented 5 months ago

@twam could I kindly ask you for a fix?

twam commented 5 months ago

It worked for me, but I’ll have a look.

Jennes commented 5 months ago

@twam If it actually runs behind a proxy like nginx, everything is fine, as far as I could tell. I don't know if loc.path is a string or something different (as I said, I don't know much about how JS works within a browser) something like … + ((loc.path && loc.path != '/') ? loc.path : "") + … could already be enough. I'm not sure if the outer parenthesis are necessary or not, maybe the ternary operator binds stronger than +

twam commented 5 months ago

With 'worked for me', I meant that I tested also a setup without proxy, i.e. directly called the web server provided by mbmd. Just rechecked and worked fine using Safari :)

Nevertheless, created a PR with removes any trailing slashes from loc.pathname which hopefully should fix the issue. At least works for me with/and without proxy with Safari and Chrome.