trunk
trunk copied to clipboard
Proxying does not respect lack of trailing slash
Say I have a test API that echos back the URI path that was called.
Note: API is running on 3000
$ curl http://localhost:3000/api
CALLED: /api
$ curl http://localhost:3000/api/
CALLED: /api/
When setting up Trunk to proxy to this endpoint it proxies to /api/ when when the original path was /api.
$ trunk --version
trunk 0.14.0
$ trunk serve --proxy-backend http://localhost:3000/api
...
Mar 05 15:23:02.819 INFO 📡 proxying /api -> http://localhost:3000/api
Mar 05 15:23:02.819 INFO 📡 server listening at 0.0.0.0:8080
$ curl http://localhost:8080/api
CALLED: /api/
$ curl http://localhost:8080/api/
CALLED: /api/
Not the biggest deal by itself but my actual API server is set to redirect /api/ to /api which causes proxying to fail.
# calling the "actual" API server now
$ curl http://localhost:3000/api
CALLED: /api
$ curl -v http://localhost:3000/api/
...
< HTTP/1.1 308 Permanent Redirect
< location: /api
...
# calling via Trunk
$ curl -v http://localhost:8080/api
...
< HTTP/1.1 308 Permanent Redirect
< location: /api
...
$ curl -v http://localhost:8080/api/
...
< HTTP/1.1 308 Permanent Redirect
< location: /api
...
PS: thanks for the amazing project, it's honestly a lifesaver. Makes working with WASM an absolute joy tbh.
I had trouble with this issue too. 🥺 This is an extraneous feature. I think It is better to optional and could be disabled as standard.
FWIW, it seems to only happen when proxying requests to the root redirect.
Assuming trunk serve --proxy-backend http://localhost:3000/api, then:
curl http://localhost:8080/apigets rewritten tohttp://localhost:3000/api/(the issue)curl http://localhost:8080/api/foobargets rewritten tohttp://localhost:3000/api/foobar(so no issue here)