mirror of
https://github.com/actix/actix-website
synced 2024-11-30 11:12:57 +01:00
Update static-files
This commit is contained in:
parent
e21219c1da
commit
1d6ccff3e8
@ -44,5 +44,5 @@ The Configuration can also be applied to directory service:
|
||||
|
||||
{{< include-example example="static-files" file="configuration_two.rs" section="config-two" >}}
|
||||
|
||||
[showfileslisting]: https://docs.rs/actix-files/0.1.2/actix_files/struct.Files.html
|
||||
[indexfile]: https://docs.rs/actix-files/0.1.2/actix_files/struct.Files.html#method.index_file
|
||||
[showfileslisting]: https://docs.rs/actix-files/0.2/actix_files/struct.Files.html
|
||||
[indexfile]: https://docs.rs/actix-files/0.2/actix_files/struct.Files.html#method.index_file
|
||||
|
@ -4,6 +4,7 @@ version = "1.0.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0"
|
||||
actix-files = "0.1"
|
||||
actix-web = "2.0"
|
||||
actix-rt = "1.0"
|
||||
actix-files = "0.2"
|
||||
mime = "*"
|
||||
|
@ -3,7 +3,7 @@ use actix_files as fs;
|
||||
use actix_web::http::header::{ContentDisposition, DispositionType};
|
||||
use actix_web::{web, App, Error, HttpRequest, HttpServer};
|
||||
|
||||
fn index(req: HttpRequest) -> Result<fs::NamedFile, Error> {
|
||||
async fn index(req: HttpRequest) -> Result<fs::NamedFile, Error> {
|
||||
let path: std::path::PathBuf = req.match_info().query("filename").parse().unwrap();
|
||||
let file = fs::NamedFile::open(path)?;
|
||||
Ok(file
|
||||
@ -14,11 +14,11 @@ fn index(req: HttpRequest) -> Result<fs::NamedFile, Error> {
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
#[actix_rt::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| App::new().route("/{filename:.*}", web::get().to(index)))
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.bind("127.0.0.1:8088")?
|
||||
.run()
|
||||
.unwrap();
|
||||
.await
|
||||
}
|
||||
// </config-one>
|
||||
|
@ -2,7 +2,8 @@
|
||||
use actix_files as fs;
|
||||
use actix_web::{App, HttpServer};
|
||||
|
||||
pub fn main() {
|
||||
#[actix_rt::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| {
|
||||
App::new().service(
|
||||
fs::Files::new("/static", ".")
|
||||
@ -10,9 +11,8 @@ pub fn main() {
|
||||
.use_last_modified(true),
|
||||
)
|
||||
})
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.bind("127.0.0.1:8088")?
|
||||
.run()
|
||||
.unwrap();
|
||||
.await
|
||||
}
|
||||
// </config-two>
|
||||
|
@ -2,13 +2,13 @@
|
||||
use actix_files as fs;
|
||||
use actix_web::{App, HttpServer};
|
||||
|
||||
pub fn main() {
|
||||
#[actix_rt::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| {
|
||||
App::new().service(fs::Files::new("/static", ".").show_files_listing())
|
||||
})
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.bind("127.0.0.1:8088")?
|
||||
.run()
|
||||
.unwrap();
|
||||
.await
|
||||
}
|
||||
// </directory>
|
||||
|
@ -7,18 +7,18 @@ use actix_files::NamedFile;
|
||||
use actix_web::{HttpRequest, Result};
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn index(req: HttpRequest) -> Result<NamedFile> {
|
||||
async fn index(req: HttpRequest) -> Result<NamedFile> {
|
||||
let path: PathBuf = req.match_info().query("filename").parse().unwrap();
|
||||
Ok(NamedFile::open(path)?)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[actix_rt::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:8088")
|
||||
.unwrap()
|
||||
.bind("127.0.0.1:8088")?
|
||||
.run()
|
||||
.unwrap();
|
||||
.await
|
||||
}
|
||||
// </individual-file>
|
||||
|
Loading…
Reference in New Issue
Block a user