commit 7d1d89523b0c6553be911c84c6c231c4d149f3ad
parent 89548dbf788652d0b6701bebbd22ed5eca64577f
Author: Charlie Stanton <charlie@shtanton.com>
Date: Wed, 5 Aug 2020 13:01:49 +0100
Adds a redirect to the homepage
Diffstat:
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/web-server/src/main.rs b/web-server/src/main.rs
@@ -1,5 +1,5 @@
-use actix_web::{web, App, HttpRequest, HttpServer, Result};
use actix_files::NamedFile;
+use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Result, http};
use std::path::PathBuf;
struct AppState {
@@ -20,8 +20,15 @@ async fn main() -> std::io::Result<()> {
return Ok(());
}
let htmldir = args[1].to_string();
- HttpServer::new(move || App::new().data(AppState {htmldir: htmldir.clone()}).route("/{filename:.*}", web::get().to(file)))
- .bind(format!("127.0.0.1:{}", args[2]))?
- .run()
- .await
+ HttpServer::new(move || {
+ App::new()
+ .data(AppState {
+ htmldir: htmldir.clone(),
+ })
+ .route("/", web::get().to(|| HttpResponse::PermanentRedirect().header(http::header::LOCATION, "/index.html").finish()))
+ .route("/{filename:.*}", web::get().to(file))
+ })
+ .bind(format!("127.0.0.1:{}", args[2]))?
+ .run()
+ .await
}