1
0
mirror of https://github.com/actix/actix-website synced 2024-11-25 09:12:42 +01:00
actix-website/examples/static-files/src/main.rs

25 lines
621 B
Rust
Raw Normal View History

pub mod configuration;
pub mod configuration_two;
pub mod directory;
2019-06-26 10:27:25 +02:00
2019-06-17 23:35:47 +02:00
// <individual-file>
use actix_files::NamedFile;
2019-06-28 19:31:30 +02:00
use actix_web::{HttpRequest, Result};
2019-06-17 23:35:47 +02:00
use std::path::PathBuf;
2019-12-28 19:36:24 +01:00
async fn index(req: HttpRequest) -> Result<NamedFile> {
2019-06-26 10:27:25 +02:00
let path: PathBuf = req.match_info().query("filename").parse().unwrap();
2019-06-17 23:35:47 +02:00
Ok(NamedFile::open(path)?)
}
2020-09-12 17:21:54 +02:00
#[actix_web::main]
2019-12-28 19:36:24 +01:00
async fn main() -> std::io::Result<()> {
2019-06-28 19:31:30 +02:00
use actix_web::{web, App, HttpServer};
2019-06-26 10:27:25 +02:00
HttpServer::new(|| App::new().route("/{filename:.*}", web::get().to(index)))
2020-09-12 17:21:54 +02:00
.bind("127.0.0.1:8080")?
2019-06-26 10:27:25 +02:00
.run()
2019-12-28 19:36:24 +01:00
.await
2019-06-17 23:35:47 +02:00
}
// </individual-file>