Skip to content

Conversation

wch
Copy link
Collaborator

@wch wch commented Oct 13, 2023

Previously, in calls to App(), the static_assets could only be a single directory, as in:

App(..., static_assets=Path(__file_).parent / "www")

This means that the www/ subdirectory on disk would be mounted at /.

This PR makes it possible to pass in multiple items, mounted at multiple locations. The API looks like this:

App(
  static_assets= {
    "lib" : Path(__file__).parent / "lib",
    "image.jpg": Path(__file__).parent / "image.jpg"
  }
)

This can be done more concisely by using a dict comprehension, as in:

_static_assets = ["lib", "image.jpg"]
_static_assets = {"/" + sa: Path(__file__).parent / sa for sa in _static_assets}

Unfortunately, I don't think there's a way to avoid passing in __file__ somehow, at least not without doing something really hacky.

@wch wch merged commit 54101ac into main Oct 14, 2023
@wch wch deleted the multiple-static-assets branch October 14, 2023 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant