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
Catch-all route doesn't work when static_folder ends in forwardslash #3452
Comments
I updated my code above after realising a logical flaw in my code. This comment is about the logical flaw in my code. @app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def catch_all(path):
build_folder = dir_path.joinpath("frontend", "build")
if path != "" and os.path.exists(dir_path.joinpath(build_folder, path)):
if path.count("/") > 1:
[path, filename] = path.rsplit("/", maxsplit=1)
return send_from_directory(dir_path.joinpath(build_folder, path), filename)
else:
filename = path
return send_from_directory(dir_path.joinpath(build_folder), filename)
else:
return render_template("index.html") The bug still remains that a catch-all route won't catch anything when there is a trailing slash in the static_folder parameter. |
Finally released 1.1.2 with this. |
Flask 1.1.2 changed its behavior around static endpoints. Now, an eventual forward slash ('/') at the end of the url will be stripped out. See pallets/flask#3452
Flask 1.1.2 changed its behavior around static endpoints. Now, an eventual forward slash ('/') at the end of the url will be stripped out. See pallets/flask#3452
Flask 1.1.2 changed its behavior around static endpoints. Now, an eventual forward slash ('/') at the end of the url will be stripped out. See pallets/flask#3452
There was a bugfix for the static folder logic that caused a test failure. See more details here: pallets/flask#3452
There was a bugfix for the static folder logic that caused a test failure. See more details here: pallets/flask#3452
I am trying to serve a React app with Flask. The React app uses React Router which means some routes should simply be handled by React. To achieve this one can usually use a catch-all route that returns the index.html. I first couldn't get the catch-all route to work at all, and then I got it working by removing the trailing slash for the
static_folder
parameter when calling Flask.Expected Behavior
When one enter a path with trailing forward slash in the
static_folder
parameter for flask.Flask() it shouldn't affect whether a catch-all route goes into effect or not.In the below code remove the trailing slash for the
static_folder
and you are able to reach the catch-all route (home function) by entering a random route like/something
.Actual Behavior
Steps to reproduce
/
/something
and see that you get 404 Not Found.Environment
The text was updated successfully, but these errors were encountered: