-
-
Notifications
You must be signed in to change notification settings - Fork 697
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
Incorrect URLs when served behind a proxy with base_url set #838
Comments
Have you tried this without the This is the test I used to ensure this feature works - it scrapes all of the links on a bunch of different pages. Could it be missing something here? Lines 1233 to 1274 in 647c5ff
|
Hmm, I haven't tried removing Looking a little more at the code, I think the issue here is that the behaviour of In a mount situation, it is perfectly fine to construct URLs reusing the domain and path from the request. In a proxy situation, it never is, as the domain and path in the request are not the domain and path that the non-proxy client actually needs to use. That is, links which include the Apache → Datasette request origin, The tests you pointed to also reflect this in two ways:
Apps that support being proxied automatically support being mounted, but apps that only support being mounted don't automatically support being proxied. |
I also am seeing the same issue with an Apache setup (same even w/o But also want to say thanks for a great tool (this issue not withstanding)! |
+1! |
Tracking ticket: #1023 |
OK, I've made a ton of improvements to how the @tsibley @tballison @ChristopherWilks I'd really appreciate your help testing this alpha! You can install it with:
It should work with just |
I'm trying to run something behind a MyBinder proxy, but seem to have something set up incorrectly and not sure what the fix is? I'm starting datasette with jupyter-server-proxy setup:
where the
but these seem to also need a base_url prefix set somehow? Currently, the generated HTML loads properly but internal links are incorrect; eg they take the form The main css is loaded correctly: |
OK, this should be working now. You can use the |
Thanks; just a note that the |
Unpins Datasette and upgrades to the latest version. Adjusts custom page styles and command-line options for upstream changes. Removes the link-fixing JS hack now that base_url is properly supported.¹ There is still one bug related to base_url² which affects custom pages like our barcode dialer. I've worked around this by symlinking dial.html under the expected production base_url. When the bug is resolved, the symlink can be removed. ¹ simonw/datasette#838 ² simonw/datasette#1238
@simonw Unfortunately this issue as I reported it is not actually solved in version 0.55. Every link which is returned by the What I wrote originally still stands:
Would you prefer to re-open this issue or have me create a new one? |
Let's reopen this. |
The biggest challenge here I think is to replicate the exact situation here this happens in a Python unit test. The fix should be easy once we have a test in place. |
Restores to the previous state before I removed it a little too-optimistically in "Upgrade Datasette" (ee654fb). Small change to come in a separate commit for visibility. I thought the bad faceting and pagination links¹ were fixed with Datasette 0.55, but after further testing, it turns out they're not.² ¹ simonw/datasette#838 ² simonw/datasette#838 (comment)
Nod. The problem with the tests is that they're ignoring the origin (hostname, port) of links. In a reverse proxy situation, the frontend request origin is different than the backend request origin. The problem is Datasette generates links with the backend request origin. |
I think this could be solved by one of:
Option 1 seems like the easiest to me, if you can get away with never having to generate an absolute URL. |
I'm running
datasette serve --config base_url:/foo/ …
, proxying to it with this Apache config:and then accessing it via
https://example.com/foo/
.Although many of the URLs in the pages are correct (presumably because they either use absolute paths which include
base_url
or relative paths), the faceting and pagination links still use fully-qualified URLs pointing athttp://localhost:8001
.I looked into this a little in the source code, and it seems to be an issue anywhere
request.url
orrequest.path
is used, as these contain the values for the request between the frontend (Apache) and backend (Datasette) server. Those properties are primarily used via thepath_with_…
family of utility functions and theDatasette.absolute_url
method.The text was updated successfully, but these errors were encountered: