mirror of
https://github.com/actix/examples
synced 2024-11-23 22:41:07 +01:00
Fixed "Method not allowed" on the todo app due to 307 redirect not ch… (#599)
fixes https://github.com/actix/examples/issues/598
This commit is contained in:
parent
e353c7ae11
commit
1baca5fd21
@ -1,5 +1,6 @@
|
|||||||
use actix_files::NamedFile;
|
use actix_files::NamedFile;
|
||||||
use actix_session::Session;
|
use actix_session::Session;
|
||||||
|
use actix_web::http::StatusCode;
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
dev, error, middleware::ErrorHandlerResponse, web, Error, HttpResponse, Responder, Result,
|
dev, error, middleware::ErrorHandlerResponse, web, Error, HttpResponse, Responder, Result,
|
||||||
};
|
};
|
||||||
@ -50,7 +51,7 @@ pub async fn create(
|
|||||||
) -> Result<impl Responder, Error> {
|
) -> Result<impl Responder, Error> {
|
||||||
if params.description.is_empty() {
|
if params.description.is_empty() {
|
||||||
session::set_flash(&session, FlashMessage::error("Description cannot be empty"))?;
|
session::set_flash(&session, FlashMessage::error("Description cannot be empty"))?;
|
||||||
Ok(Redirect::to("/"))
|
Ok(Redirect::to("/").using_status_code(StatusCode::FOUND))
|
||||||
} else {
|
} else {
|
||||||
db::create_task(params.into_inner().description, &pool)
|
db::create_task(params.into_inner().description, &pool)
|
||||||
.await
|
.await
|
||||||
@ -58,7 +59,7 @@ pub async fn create(
|
|||||||
|
|
||||||
session::set_flash(&session, FlashMessage::success("Task successfully added"))?;
|
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}");
|
let msg = format!("Unsupported HTTP method: {unsupported_method}");
|
||||||
return Err(error::ErrorBadRequest(msg));
|
return Err(error::ErrorBadRequest(msg));
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
.using_status_code(StatusCode::FOUND))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn toggle(
|
async fn toggle(
|
||||||
|
Loading…
Reference in New Issue
Block a user