mirror of
https://github.com/actix/examples
synced 2025-02-20 08:20:32 +01:00
25 lines
1007 B
Rust
25 lines
1007 B
Rust
use actix_files::Files;
|
|
use actix_web::{middleware, App, HttpServer};
|
|
|
|
#[actix_web::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
std::env::set_var("RUST_LOG", "actix_web=info");
|
|
env_logger::init();
|
|
|
|
HttpServer::new(|| {
|
|
App::new()
|
|
// Enable the logger.
|
|
.wrap(middleware::Logger::default())
|
|
// 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"))
|
|
})
|
|
.bind("127.0.0.1:8080")?
|
|
.run()
|
|
.await
|
|
}
|