SolvedRocket Static file serving

First off: let me just say that Rocket is very nice and has been a pleasure to use, kudos!

I looked around the docs and couldn't find any support for serving a set of static files from a directory. This is something that I've seen supported in every web framework I've ever used. As an arbitrary example, here's how it works in Flask. This is a pretty common pattern to serve things like CSS files and JS scripts, so I think it would be useful to have. Obviously one can serve individual files by just having a handler that returns a File, but this seems like generally useful functionality. Ideally one would simply be able to do something like rocket::ignite().mount("/static", StaticFiles(some_path).

25 Answers

✔️Accepted Answer

@luser Perhaps something in contrib that you can simply mount. So it would look something like:

use rocket_contrib::StaticFiles;

rocket::ignite().mount("/path_to_serve_on", StaticFiles::from("/path_to_serve_from"));

This would presumably serve files from the /path_to_serve_from directory at the path /path_to_serve_on.

I think something like this would be nice, though I'm not sure if it's actually possible to do this in a clean way at the moment. I'll look into it.

Other Answers:

@quadrupleslap See the docs here and here.

I am not sure if this helps.. Have you seen the the static_files example ?

More Issues: