1
0
mirror of https://github.com/actix/actix-website synced 2025-01-23 00:25:55 +01:00
2024-02-06 14:49:05 +00:00

25 lines
625 B
Rust

pub mod configuration;
pub mod configuration_two;
pub mod directory;
// <individual-file>
use actix_files::NamedFile;
use actix_web::HttpRequest;
use std::path::PathBuf;
async fn index(req: HttpRequest) -> actix_web::Result<NamedFile> {
let path: PathBuf = req.match_info().query("filename").parse().unwrap();
Ok(NamedFile::open(path)?)
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
use actix_web::{web, App, HttpServer};
HttpServer::new(|| App::new().route("/{filename:.*}", web::get().to(index)))
.bind(("127.0.0.1", 8080))?
.run()
.await
}
// </individual-file>