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

Start static directory support #1024

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

dave42w
Copy link
Contributor

@dave42w dave42w commented Nov 11, 2024

Description

This PR fixes #1005

Work In Progress

Summary

This PR provides a simple way to add a static directory for the Robyn app and each SubRouter. It calls serve_directory but with fewer arguments and simple defaults. The goal will be to make it a one line addition eg

change from (in the initial example at https://robyn.tech/documentation/example_app/modeling_routes )

app = Robyn(__file__)

@app.post("/crimes")

to

app = Robyn(__file__)
app.add_static_files_directory() #using a sane default directory path and "static" as the route both customisable via arguments

@app.post("/crimes")

For the subrouter the same ( https://robyn.tech/documentation/example_app/subrouters_and_views )
'''
frontend = SubRouter(name, prefix="/frontend")
frontend.add_static_files_directory() #using a sane default directory path and "static" as the route both customisable via arguments

@frontend.get("/")
'''

what I want to support are these routes /static/crimes.css and '/frontend/static/fronts.css' (where frontend is the object name not the route prefix)

Then we can add support to templating allowing us simple access to static files in templates which won't change when the route prefix for frontend changes

get_static_url("crimes.css") 
get_static_url("frontend/fronts.css") 

PR Checklist

Please ensure that:

  • The PR contains a descriptive title
  • The PR contains a descriptive summary of the changes
  • You build and test your changes before submitting a PR.
  • You have added relevant documentation
  • You have added relevant tests. We prefer integration tests wherever possible

Pre-Commit Instructions:

Copy link

vercel bot commented Nov 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
robyn ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 12, 2024 3:07am

@dave42w
Copy link
Contributor Author

dave42w commented Nov 17, 2024

Hi @sansyrox
I just wanted to check if you would accept this PR if I complete the code (obviously in an acceptable way)
Thanks
Dave

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.

Serving static files
1 participant