Skip to content
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

[Question] Serving static files - AsyncApp #1965

Open
gastonoterom opened this issue Aug 20, 2024 · 0 comments
Open

[Question] Serving static files - AsyncApp #1965

gastonoterom opened this issue Aug 20, 2024 · 0 comments

Comments

@gastonoterom
Copy link

Hello! First and foremost, awesome library.

I am working on a project, it's migrating an API from Tornado to Connexion. Besides the main API, this server has a landing page which needs resources from the 'static' folder to render correctly.

I've read some issues to solve this:

But we decided to use the AsyncApp instead of the FlaskApp.

I figured that since the connexion middleware uses starlette, this can be done to mount the static files folder:

starlette_router = app._middleware_app.router

starlette_router.routes.append(
  Mount("/static", app=StaticFiles(directory="static"), name="static"),
)

This currently works.

My questions are these:

  • Is there any way to do something similar without accessing protected attributes?
  • Is this even supported by the connexion framework?
  • Is this too much of a specific requirement that it shouldn't be part of the library?

If anyone is interest in this I can create a PR to add functionality + documentation to do this.

app.mount_static_files_directory(
  path="/static",
  directory="static",
  name="static",
)

Thanks

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

No branches or pull requests

1 participant