Now it works correctly with react router
This commit is contained in:
parent
df2a0f3c9a
commit
1f8531711f
1 changed files with 28 additions and 4 deletions
32
src/main.rs
32
src/main.rs
|
|
@ -1,5 +1,10 @@
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
use actix_files;
|
use actix_files;
|
||||||
use actix_web::{App, HttpServer};
|
use actix_web::{
|
||||||
|
dev::{ServiceRequest, ServiceResponse},
|
||||||
|
App, HttpServer,
|
||||||
|
};
|
||||||
use clap::{arg, command, Parser};
|
use clap::{arg, command, Parser};
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
|
|
@ -28,10 +33,29 @@ async fn main() -> std::io::Result<()> {
|
||||||
let bind_addr = format!("{}:{}", args.host, args.port);
|
let bind_addr = format!("{}:{}", args.host, args.port);
|
||||||
println!("Listening on http://{}", bind_addr);
|
println!("Listening on http://{}", bind_addr);
|
||||||
|
|
||||||
|
let index_path = Path::new(args.serve_dir.as_str())
|
||||||
|
.join(args.index_file.as_str())
|
||||||
|
.display()
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
let mount_point = args.mount.clone();
|
||||||
|
|
||||||
HttpServer::new(move || {
|
HttpServer::new(move || {
|
||||||
App::new().default_service(
|
let index_path = index_path.to_owned();
|
||||||
actix_files::Files::new(&args.mount, args.serve_dir.as_str())
|
|
||||||
.index_file(args.index_file.as_str()),
|
App::new().service(
|
||||||
|
actix_files::Files::new(&mount_point, args.serve_dir.as_str())
|
||||||
|
.index_file(args.index_file.as_str())
|
||||||
|
.default_handler(move |req: ServiceRequest| {
|
||||||
|
let (http_req, _payload) = req.into_parts();
|
||||||
|
let index_path = index_path.to_owned();
|
||||||
|
|
||||||
|
async {
|
||||||
|
let response =
|
||||||
|
actix_files::NamedFile::open(index_path)?.into_response(&http_req);
|
||||||
|
Ok(ServiceResponse::new(http_req, response))
|
||||||
|
}
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.bind(bind_addr)?
|
.bind(bind_addr)?
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue