More C&P from Actix docs.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
"tokio-util 0.7.0",
]
+[[package]]
+name = "actix-files"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d81bde9a79336aa51ebed236e91fc1a0528ff67cfdf4f68ca4c61ede9fd26fb5"
+dependencies = [
+ "actix-http",
+ "actix-service",
+ "actix-utils",
+ "actix-web",
+ "askama_escape",
+ "bitflags",
+ "bytes",
+ "derive_more",
+ "futures-core",
+ "http-range",
+ "log 0.4.16",
+ "mime 0.3.16",
+ "mime_guess",
+ "percent-encoding 2.1.0",
+ "pin-project-lite",
+]
+
[[package]]
name = "actix-http"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbf56136a5198c7b01a49e3afcbef6cf84597273d298f54432926024107b0109"
+[[package]]
+name = "askama_escape"
+version = "0.10.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341"
+
[[package]]
name = "async-trait"
version = "0.1.52"
"pin-project-lite",
]
+[[package]]
+name = "http-range"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573"
+
[[package]]
name = "httparse"
version = "1.6.0"
name = "otter-daemon"
version = "0.7.3"
dependencies = [
+ "actix-files",
"actix-web",
"fehler",
"futures",
name="actix-test"
path="actix-test.rs"
+[[bin]]
+name="actix-files-example"
+path="actix-files-example.rs"
+
[dependencies]
structopt="0.3"
actix-web = "4"
+actix-files = "0.6"
rocket = { version="^0.4.6", features=["sse"] }
rocket_contrib = { version="0.4", default-features=false, features=["tera_templates", "helmet", "json", "serve"] }
--- /dev/null
+use actix_files::Files;
+use actix_web::{middleware::Logger, App, HttpServer};
+use otter::imports::*;
+
+#[actix_web::main]
+async fn main() -> std::io::Result<()> {
+ env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
+
+ log::info!("starting HTTP server at http://localhost:8080");
+
+ HttpServer::new(|| {
+ App::new()
+ // We allow the visitor to see an index of the images at `/images`.
+ .service(Files::new("/images", "static/images/").show_files_listing())
+ // Serve a tree of static files at the web root and specify the index file.
+ // Note that the root path should always be defined as the last item. The paths are
+ // resolved in the order they are defined. If this would be placed before the `/images`
+ // path then the service for the static images would never be reached.
+ .service(Files::new("/", "./static/root/").index_file("index.html"))
+ // Enable the logger.
+ .wrap(Logger::default())
+ })
+ .bind(("127.0.0.1", 8080))?
+ .run()
+ .await
+}