Static files handler

For the other paths that were not listed in the previous scope, we will use a handler that will return a file's content from a folder to serve static assets. The handler method expects a prefix for a path, and a type that implements the Handler trait. In our case, we will use a ready-to-use static files handler, actix_web::fs::StaticFiles. It needs a path to a local folder and we can also set an index file by calling the index_file method:

app.handler(
"/",
fs::StaticFiles::new("./static/").unwrap().index_file("index.html")
)

Now, if a client send a GET request to a path such as /index.html or /css/styles.css, then the StaticFiles handler will send the contents of the corresponding files from the ./static/ local folder.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.136.63