-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
Serving static files #1005
Comments
See #996 (comment) |
I think that my plan in PR #1024 makes this even simpler. |
Hey @dave42w 👋
Why can't someone just create a static folder themself? Why do we need a new default? |
My PR updates this. The reason for it is a) to be simpler than serve_directory is at present and b) to work for subroutes as well I'm suggesting:
What I want to support from templates is
It would even support
there could be a fallback so that if it doesn't find crimes.css in the subrouter static directory it looks in the main one. That could provide a nice fallback support. |
Robyn has some powerful features for serving static files. However, there are a couple of issues/
Hidden Documentation
At the moment the docs for serving files are "hidden" in "File Uploads" https://robyn.tech/documentation/api_reference/file-uploads
Can we make this more visible by moving it to the top level of API reference (and preferably renaming it to something like "Serving Static Files")
I tried editing the docs but npm hates me ;-)
Simple default
[Update] this PR starts realm code and I think it is simpler/better #1024
As we can serve directories (for CSS, etc.), providing a default would save people a lot of reading.
I'd like us to add
ROBYN_STATIC_FILE_DIRECTORY
to the robyn.env file. If this is set then we automatically call app.serve_directory() to provide this static directory under the URL "/static/"SubRouters
It would also seem sensible be able to add static directories to each SubRouter eg by passing a Bool argument to the function
frontend = SubRouter(name, prefix="/frontend", True) ## make /frontend/static/ serve files
frontend = SubRouter(name, prefix="/frontend", False) ## No support for /frontend/static/
frontend = SubRouter(name, prefix="/frontend") ## Default to False ie No support for /frontend/static/
url_for
The flask version of url_for supports static files but only for a single directory.
I'm thinking we could have
url_for('static', 'filename.css')
to serve from the application-wide static directoryThen for the subrouters we have
url_for('static', 'filename.css', subroute='RouterName')
This way we have minimal impact on our templates if we restructure the project.
The text was updated successfully, but these errors were encountered: