From 1baca5fd21484215478daf22b2246402bcd82fb6 Mon Sep 17 00:00:00 2001 From: Rouslan Grabar Date: Mon, 9 Jan 2023 14:21:39 +0400 Subject: [PATCH] =?UTF-8?q?Fixed=20"Method=20not=20allowed"=20on=20the=20t?= =?UTF-8?q?odo=20app=20due=20to=20307=20redirect=20not=20ch=E2=80=A6=20(#5?= =?UTF-8?q?99)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes https://github.com/actix/examples/issues/598 --- basics/todo/src/api.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/basics/todo/src/api.rs b/basics/todo/src/api.rs index ae8900d..00725ce 100644 --- a/basics/todo/src/api.rs +++ b/basics/todo/src/api.rs @@ -1,5 +1,6 @@ use actix_files::NamedFile; use actix_session::Session; +use actix_web::http::StatusCode; use actix_web::{ dev, error, middleware::ErrorHandlerResponse, web, Error, HttpResponse, Responder, Result, }; @@ -50,7 +51,7 @@ pub async fn create( ) -> Result { if params.description.is_empty() { session::set_flash(&session, FlashMessage::error("Description cannot be empty"))?; - Ok(Redirect::to("/")) + Ok(Redirect::to("/").using_status_code(StatusCode::FOUND)) } else { db::create_task(params.into_inner().description, &pool) .await @@ -58,7 +59,7 @@ pub async fn create( session::set_flash(&session, FlashMessage::success("Task successfully added"))?; - Ok(Redirect::to("/")) + Ok(Redirect::to("/").using_status_code(StatusCode::FOUND)) } } @@ -85,7 +86,8 @@ pub async fn update( let msg = format!("Unsupported HTTP method: {unsupported_method}"); return Err(error::ErrorBadRequest(msg)); } - })) + }) + .using_status_code(StatusCode::FOUND)) } async fn toggle(