Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support running under subpath #78

Open
HESOYAM-abuser opened this issue Nov 2, 2024 · 2 comments
Open

Support running under subpath #78

HESOYAM-abuser opened this issue Nov 2, 2024 · 2 comments

Comments

@HESOYAM-abuser
Copy link

Hi @muety

I set ANCHR_PUBLIC_URL="http://127.0.0.1:8080/anchr" to define my base URL root, but I'm encountering two issues:

  1. Response URL Issue: When making requests to http://127.0.0.1:8080/anchr, the response URL redirects to http://127.0.0.1:8080/, which causes routing errors.

  2. API and Resource Path Issue: When shortening links or uploading images, the requests go to http://127.0.0.1:8080/api instead of the expected http://127.0.0.1:8080/anchr/api. The responses also seem incorrect.

Expected Behavior

  • Responses should be directed to http://127.0.0.1:8080/anchr.
  • Requests for resources like APIs and uploaded images should follow the base URL and go to http://127.0.0.1:8080/anchr/api.

Actual Behavior

  • Responses are directed to http://127.0.0.1:8080/.
  • Resource requests ignore the base URL path, going to http://127.0.0.1:8080/api instead of http://127.0.0.1:8080/anchr/api.

Steps to Reproduce

  1. Set ANCHR_PUBLIC_URL="http://127.0.0.1:8080/anchr".
  2. Attempt to shorten a link or upload an image.
  3. Observe the response URL and the API/resource request paths.

Possible Solution

  • Adjust the routing to ensure the response and API/resource requests respect the base URL path.
@HESOYAM-abuser
Copy link
Author

Screenshot from 2024-11-02 13-03-47

There is another issue regarding the URLs for images and short links. For images, the URL is fetched from the request header; however, for short links, it retrieves the URL from ANCHR_PUBLIC_URL. This discrepancy can be observed in the image I provided. I believe it would be better to source both from a single location to avoid potential problems.

@muety
Copy link
Owner

muety commented Nov 2, 2024

Thanks for bringing this up!

Currently, ANCHR_PUBLIC_URL is expected to be the root of the application, i.e. that path part of the URL is expected to effectively be /. A common approach to run applications under a subpath is to use a reverse proxy instead, e.g. see this example. However, Anchr doesn't support their either, currently.

I'm reluctant to add logic for running under a subpath to the application itself, as you suggested. While it would be possible to extend the role of ANCHR_PUBLIC_URL to fully customize frontend- and API URL's, it's quite uncommon, I think. I don't think I remember having seen something like that somewhere else before.

However, it would be totally legitimate to add support for running under a subpath when behind a reverse proxy. This would require to:

  1. Dynamically set <a base href="...">
  2. Replace all absolute API endpoint paths (/api/xyz) by relative paths (api/xyz) in the frontend
  3. Make "Logout" button redirect to actual base path instead of /
  4. ...

I'll add this as a feature request, but - honestly - won't be getting to it too soon, unfortunately.

@muety muety changed the title Issue with Base URL Configuration Support running under subpath Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants