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

base_url getting appended twice in redirects when applying filters? #2347

Open
EternityForest opened this issue May 15, 2024 · 0 comments
Open

Comments

@EternityForest
Copy link

When running under a custom base URL, the "Apply" button for filters does not seem to work. It redirects to a url starting with /baseurl/baseurl/ and the extra copy of the base URL messes things up.

I'm able to get things working with the following changes, but I'm not sure if the whole thing is just user error on my end.
If not, I can make a PR.

class Urls:
    def __init__(self, ds):
        self.ds = ds

    def path(self, path, format=None, already_prefixed=False):
        if not isinstance(path, PrefixedUrlString):
            if path.startswith("/"):
                path = path[1:]
            if not already_prefixed:
                path = self.ds.setting("base_url") + path
            else:
                path = "/" + path
        if format is not None:
            path = path_with_format(path=path, format=format)
        return PrefixedUrlString(path)
async def _redirect_if_needed(datasette, request, resolved):
    # Handle ?_filter_column
    redirect_params = filters_should_redirect(request.args)
    if redirect_params:
        return _redirect(
            datasette,
            request,
            datasette.urls.path(path_with_added_args(request, redirect_params), already_prefixed=True),
            forward_querystring=False,
        )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant