emmett-framework / granian

A Rust HTTP server for Python applications
BSD 3-Clause "New" or "Revised" License
2.9k stars 86 forks source link

Feature request: static file serving support #444

Open matthiask opened 1 day ago

matthiask commented 1 day ago

From #97

Nginx serves static files

Now that can be (IMO) a more interesting feature request for Granian.

I think it would be very useful to have some sort of static file serving functionality.

Either something like nginx's try_files where granian could first check a folder for a match, and if not, fall back to the RSGI/ASGI/WSGI app, or maybe just support mapping URL paths to folders.

A plus would be if granian could optionally serve those files with far-future expiry headers. nginx does the following when using expires max:

The max parameter sets “Expires” to the value “Thu, 31 Dec 2037 23:55:55 GMT”, and “Cache-Control” to 10 years.

From https://nginx.org/en/docs/http/ngx_http_headers_module.html

This is the only feature which is missing for me to make granian a one-stop solution to serve everything with a single ingress, no sidecars or similar.

(I'd be willing to work on this with some guidance, or fund it if that's helpful.)

gi0baro commented 1 day ago

I think this would be a useful feature for a lot of deployments out there, I definitely agree this should be implemented in the near future. I don't think this will be in time for 1.7, but possibly we can target 1.8.

In terms of implementation, here are some notes I can think of at the moment: