Configuring an HTTP server to perform file serving
The last recipes were really useful for building web services, but let's take a look at how to do the thing HTTP was originally created for: serving HTML files to the web.
How to do it...
- Open the
Cargo.toml
file that has been generated for you. - Under
[dependencies]
, if you didn't do so in the last recipe, add the following lines:
futures = "0.1.18" hyper = "0.11.21"
- If you want, you can go to futures' (https://crates.io/crates/futures) and hyper's (https://crates.io/crates/hyper) crates.io pages to check for the newest version and use that one instead.
- In the folder
chapter-nine
, create a folder calledfiles
. - In the folder
files
, create a file calledindex.html
and add the following code to it:
<!doctype html> <html> <head> <link rel="stylesheet" type="text/css" href="/style.css"> <title>Home</title> </head> <body> <h1>Home</h1> <p>Welcome. You can access other files...