1
0
mirror of https://github.com/actix/examples synced 2025-02-13 05:52:20 +01:00

25 lines
1010 B
Rust
Raw Normal View History

use actix_files::Files;
2019-03-09 22:38:15 -08:00
use actix_web::{middleware, App, HttpServer};
2020-09-12 16:49:45 +01:00
#[actix_web::main]
2019-12-07 23:59:24 +06:00
async fn main() -> std::io::Result<()> {
2019-03-09 22:38:15 -08:00
std::env::set_var("RUST_LOG", "actix_web=info");
env_logger::init();
2019-03-09 22:38:15 -08:00
HttpServer::new(|| {
2018-05-20 21:03:29 -07:00
App::new()
// Enable the logger.
2019-03-26 04:29:00 +01:00
.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"))
2019-03-09 18:03:09 -08:00
})
2022-02-17 20:22:36 +00:00
.bind(("127.0.0.1", 8080))?
2019-12-25 20:48:33 +04:00
.run()
2019-12-07 23:59:24 +06:00
.await
}