-
-
Notifications
You must be signed in to change notification settings - Fork 210
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
Add the basics to add serving of static files #36
Conversation
Just an idea can't we load the file from rust and not touch python at all, I.e add app.serve("localpath", "publication") |
@JackThomson2 , I can see three problems in this, do correct me if I am wrong:
|
Hi so,
Also a note if we do plan to use this approach, we should use the built-in async file reading so it wont block Jack |
I can definitely understand the benefits of the approach mentioned by you. The decorator syntax is really loved in the python ecosystem. We can implement both of the approaches. The current approach(including python) will be used to serve smaller single html files and it will also be used to serve json responses. We will also allow the way you suggested to serve larger html files and mounting directories. This way we will still preserve the elegance of the code when required. Since no one really serves directories as a response to POST requests but single html files are not so uncommon.
Can you please share a snippet on how overloading is done in rust? I could not find it anywhere.
Are you talking about this? https://docs.rs/async-fs/1.5.0/async_fs/ |
Interesting, I've never really seen HTML returned from a POST request, I always thought POST as submitting data to the server and GET getting data from the server. For overloading, i tend to have two methods with similar names and the one with less parameters fills in the default when calling the other. I guess this may be more appropriate as we're using tokio: https://docs.rs/tokio/1.8.0/tokio/fs/index.html Jack |
Dont you need at be setting correct MIME types, as a browser won't like static files returned this way |
@JackThomson2 , even though it worked well on my browser, I believe that it will be a good practice if we set mime types. |
I think errors would start to appear when using JS or other file types. |
That could be true. I will implement it in a new PR. |
Also, will we have to manage application/json and text/json separately ? |
First implementation to enable the serving of static files