typicode / hotel

🏩 A simple process manager for developers. Start apps from your browser and access them using local domains
MIT License
9.98k stars 422 forks source link

Handle paths in redirection #353

Open christianwerz opened 4 years ago

christianwerz commented 4 years ago

Inspired by https://github.com/typicode/hotel/pull/16

This allows you to do http://localhost:2000/cheatsheets/XYZ.html and have it redirect to http://localhost:68192/XYZ.html.

dbraley commented 4 years ago

Ha, I was just about to submit a PR that did exactly this (plus offered the ability to have servers configured to forward by proxy rather than redirect). Wish I'd seen this PR first, would have saved myself some time! @typicode This goes to addressing my concerns in Issue https://github.com/typicode/hotel/issues/350.

dbraley commented 4 years ago

Something minor review-like things I noticed when I rebased my forward-by-proxy code on top of this branch: The router pattern '/:id/*' doesn't seem to actually match on urls without a trailing slash, iehttp://localhost:2000/foo, so I think you need to have both patterns present. The definition let target = item.target in group.js's redirect method happens before item.target is set, which seems to be problematic when I run it locally. Additionally, path seems to convert the url to relative, rather than absolute, which I suspect is not desirable (and definitely doesn't work for proxying the request).

I took a stab at the appropriate fixes here.