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
588 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;
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)?)
}
fn main() {
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)))
.bind("127.0.0.1:8088")
.unwrap()
.run()
.unwrap();
2019-06-17 23:35:47 +02:00
}
// </individual-file>