Base path with trailing slash does not work
Describe the bug
Cannot use a base path that ends in a slash.
To Reproduce Steps to reproduce the behavior:
- In nginx reverse proxy, setup a
/wetty/location to redirect to WeTTY. - Run WeTTY with
--base /wetty/ - Try to load
http[s]://server/wetty/in a browser.
Expected behavior WeTTY loads and displays "username" prompt, etc.
Actual behavior
WeTTY redirects from /wetty/ (root path) to /wetty (outside of the base path), missing the proxied path space. The reverse proxy will then handle the request itself, e.g. searching for a file/dir at that location, and possibly generating a redirect to re-add the trailing slash, causing a redirect loop.
Desktop (please complete the following information): N/A (irrelevant to this issue)
Smartphone (please complete the following information): N/A (irrelevant to this issue)
Web Server & Reverse Proxy
- OpenBSD 7.1 amd64
- nginx/1.20.2
- nodejs v16.14.2
Additional context
Allowing WeTTY access to the /wetty path (no trailing slash) is very impractical because it mismatches with all other apps hosted on the same site, and can cause inconsistent behavior with relative redirects.
FYI I am partially working around this issue for some deployments by e.g. redirecting from /wetty to /wetty/ssh/user, though it's not working for every deployment (ones affected by #395 and/or #396), and this workaround is only feasible for cases where I want to allow access only to a specific user/app rather than providing a general use terminal for any user.
The problem seems to be caused by https://github.com/butlerx/wetty/blob/main/src/server/socketServer.ts#L45. It seems as though this must have been intended to fix a problem, but I can't see an indication of what that problem was. It doesn't make sense to require a URL without a trailing slash for the base path, because if the base path is just / then there is no way to remove the trailing slash.
Stale issue message