Skip to content

Commit

Permalink
Update app.py
Browse files Browse the repository at this point in the history
  • Loading branch information
alesanchezr authored Nov 1, 2024
1 parent 847367c commit 123b985
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ def sitemap():

# any other endpoint will try to serve it like a static file

@app.route('/admin', methods=['GET'])
def serve_any_other_file(path):
response = send_from_directory(static_file_dir, path)
response.cache_control.max_age = 0 # avoid cache memory
return response

@app.route('/admin/<path:path>', methods=['GET'])
def serve_any_other_file(path):
response = send_from_directory(static_file_dir, path)
response.cache_control.max_age = 0 # avoid cache memory
return response

@app.route('/<path:path>', methods=['GET'])
def serve_any_other_file(path):
Expand Down

2 comments on commit 123b985

@UmiKami
Copy link

@UmiKami UmiKami commented on 123b985 Nov 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @alesanchezr ,

This commit introduced an error due to the three routes having functions with the same name:

@app.route('/admin', methods=['GET'])
def serve_any_other_file(path):
    response = send_from_directory(static_file_dir, path)
    response.cache_control.max_age = 0  # avoid cache memory
    return response
@app.route('/admin/<path:path>', methods=['GET'])
def serve_any_other_file(path):
    response = send_from_directory(static_file_dir, path)
    response.cache_control.max_age = 0  # avoid cache memory
    return response

@app.route('/<path:path>', methods=['GET'])
def serve_any_other_file(path):
    if not os.path.isfile(os.path.join(static_file_dir, path)):
        path = 'index.html'
    response = send_from_directory(static_file_dir, path)
    response.cache_control.max_age = 0  # avoid cache memory
    return response

@UmiKami
Copy link

@UmiKami UmiKami commented on 123b985 Nov 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This's the error:

return f(self, *args, **kwargs)

File "/home/vscode/.local/share/virtualenvs/react-flask-hello-8vr8HM4e/lib/python3.10/site-packages/flask/sansio/app.py", line 657, in add_url_rule
raise AssertionError(
AssertionError: View function mapping is overwriting an existing endpoint function: serve_any_other_file

Please sign in to comment.