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