Skip to content

[BUG] static route example doesn't work with fastapp #768

@lucasvw

Description

@lucasvw

Describe the bug

In the docs, there is an example for serving static files:

from fasthtml.common import *

app = FastHTML()
rt = app.route
cli = Client(app)

reg_re_param("imgext", "ico|gif|jpg|jpeg|webm")

@rt(r'/static/{fn}.{ext:imgext}')
def get(fn:str, ext:str): return f"Getting {fn}.{ext}"

print(cli.get('/static/jph.ico').text)

And this works. However, when using fast_app() instead of FastHTML this no longer works:

from fasthtml.common import *

app, rt = fast_app()
cli = Client(app)

reg_re_param("imgext", "ico|gif|jpg|jpeg|webm")

@rt(r'/static/{fn}.{ext:imgext}')
def get(fn:str, ext:str): return f"Getting {fn}.{ext}"

print(cli.get('/static/jph.ico').text)

Minimal Reproducible Example
See above

Expected behavior
I expect that getting the routes through:

app = FastHTML()
rt = app.route

and

app, rt = fast_app()

would behave similarly, but they don't

Environment Information
Please provide the following version information:

  • fastlite version: 0.2.1
  • fastcore version: 1.8.7
  • fasthtml version: 0.12.22

Confirmation
Please confirm the following:

  • I have read the FAQ (https://docs.fastht.ml/explains/faq.html) --> bad link
  • I have provided a minimal reproducible example
  • I have included the versions of fastlite, fastcore, and fasthtml
  • I understand that this is a volunteer open source project with no commercial support.

Additional context
I understand that with fast_app we can also use static_path argument to hook up static files, however I still think it's a bug since there is no reason to assume rt behaves differently in both cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions