-
-
Notifications
You must be signed in to change notification settings - Fork 16.3k
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
static_url_path doesn't work if it ends with a slash #3134
Comments
I'm pretty sure urljoin always throws away existing path segments on the first arg. |
Aside, making the static url path the root is probably going to give you unexpected behavior. |
i will be taking a look at this issue |
@davidism wrote:
Could you say more (and should that be documented)? I’ve seen a number of Flask users do this (to serve a SPA that assumes it’s mounted under /) who haven’t yet seen unexpected behavior. |
The URL rule is There are better ways of serving SPAs than passing it through Flask. In development, SPAs have their own dev server that should be used, and either they or the WSGI app would set up a proxy to keep everything under one domain (Werkzeug has proxy middleware now). In production, Nginx would be configured to serve the static files and leave Flask to do backend things. |
Yes, we have it set up so SPA dev servers work in development. And in production we use gunicorn with Whitenoise to serve static files, running behind Waiter. Since the For example, we know that any route But eager to know if there are any compelling examples of nasty cases I'm missing! |
It sounds like you've only been generating the urls, not using Flask to actually serve the files. If you're using a proxy in dev and whitenoise in prod, routes that would be problematic aren't reaching Flask, so you won't see the issue. |
Meant to add, this accepted StackOverflow answer and this post (which was referenced in #348 (comment)) recommend this, so if this recommendation actually comes with caveats it'd be good to have some docs about it – should I open a new issue? |
I don't actually have a reproducible example, just a general remembering of old issues and questions. I think there were some changes to Werkzeug that may have addressed it too, but it's been too long for me to remember. If people don't seem to be running into the issue, I wouldn't worry about it for now. |
Here's a reproducible example: from flask import Flask
app = Flask(__name__, static_url_path='')
@app.route('/405/', methods=['POST'])
def hello_world():
return 'Hello, World!' For get requests this view should return 405 NotAllowed but instead returns a 404 Not Found. |
flask/flask/app.py
Line 560 in a74864e
Urljoin seems like more robust way to join urls. I just tried to set static_url_path = '/' and it failed, but static_url_path = '' succeed. IMHO, this is bad and unexpected behaviour.
The text was updated successfully, but these errors were encountered: