trunk icon indicating copy to clipboard operation
trunk copied to clipboard

Proxying does not respect lack of trailing slash

Open noc7c9 opened this issue 3 years ago • 1 comments

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.

noc7c9 avatar Mar 05 '22 04:03 noc7c9

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.

usagi avatar Sep 13 '22 13:09 usagi

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/api gets rewritten to http://localhost:3000/api/ (the issue)
  • curl http://localhost:8080/api/foobar gets rewritten to http://localhost:3000/api/foobar (so no issue here)

Ekleog avatar Nov 13 '22 18:11 Ekleog