Open mscosti opened 4 years ago
We now recommend using https://github.com/adafruit/Adafruit_CircuitPython_HTTPServer instead, and would like to discontinue supporting this library. Would that library meet your needs? I believe it already addresses what you requested here.
A very common use case for a web server is to be able to respond with static asset (files). This is primarily so that if a web browser makes an http request to your webserver, you can respond with a .html file which contains markup for a user interface. This
.html
file may also include references to other files, namely.js
or .css
, for front end javascript code and styling.A common way to achieve this in other frameworks is to specify a particular folder on the server's filesystem, and expose white listed parts or all of its contents. I.e, If a http request comes in and matches the relative path of a file in that folder, then send back an 200 with the contents of that file.
This means that you wouldn't have to manually add a particular route for every static asset you want to serve, and less boiler plate code to read and transmit the asset.
Using Flask as inspiration
Need at minimum
static_folder
, that is the path to a folder on the local filesystem that should be served.static_url_path
, that is what the web app base path would be for serving files fromstatic_folder
. If not provided, default to serving with the same base path ofstatic_folder
def send_from_directory(directory, filepath) -> return valid WSGI response
, for situations where you need to respond with a file but need to do it from your own route handler (simple example, serve this OR that file depending on some dynamic criteria)Questions
static
at path/static/
?.py
or specificallysecrets.py
/static
that are.html
,.css
,.js
, photo types, etc ?/static/
is meant for purposefully adding files you want to serve, and would not usually have a file in there you do not want public.