フォルダ階層
{root-dir}
├ asset ← 手動で作成する(静的ファイルを格納するフォルダ)
│ ├ html
│ ├ js
│ └ img
└ src
使用するライブラリ
actix-web = "4.4.0" ← web framework
actix-files = "0.6.2" ← 静的ファイルを使用するためのライブラリ
サンプルコード
use actix_files;
use actix_web::{get,App,Error,HttpRequest,HttpServer};
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
// 注:先に追加したserviceからマッチするため、
// "/"を一番最初に書くと「/js」「/img」がマッチされなくなってしまう
.service(actix_files::Files::new("/js","asset/js").show_files_listing())
.service(actix_files::Files::new("/img","asset/img").show_files_listing())
.service(actix_files::Files::new("/","asset/html").show_files_listing())
})
.bind(("0.0.0.0",8080))?
.run()
.await
}