Skip to content

Commit

Permalink
feat: フォーム作成のエントリポイントのレスポンスヘッダにLocationを含める
Browse files Browse the repository at this point in the history
  • Loading branch information
rito528 committed Oct 13, 2023
1 parent 77ecfa5 commit 03062d4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 3 additions & 2 deletions server/entrypoint/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use axum::{
Router,
};
use common::config::{ENV, HTTP};
use hyper::header::AUTHORIZATION;
use hyper::header::{AUTHORIZATION, LOCATION};
use presentation::{
auth::auth,
form_handler::{
Expand Down Expand Up @@ -83,7 +83,8 @@ async fn main() -> anyhow::Result<()> {
CorsLayer::new()
.allow_methods([Method::GET, Method::POST, Method::DELETE, Method::PATCH])
.allow_origin(Any) // todo: allow_originを制限する
.allow_headers([CONTENT_TYPE, AUTHORIZATION]),
.allow_headers([CONTENT_TYPE, AUTHORIZATION])
.expose_headers([LOCATION]),
);

let addr = SocketAddr::from(([0, 0, 0, 0], HTTP.port.parse().unwrap()));
Expand Down
12 changes: 10 additions & 2 deletions server/presentation/src/form_handler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use axum::{
extract::{Path, Query, State},
http::StatusCode,
http::{header, HeaderValue, StatusCode},
response::IntoResponse,
Json,
};
Expand All @@ -27,7 +27,15 @@ pub async fn create_form_handler(
.create_form(form.title, form.description)
.await
{
Ok(id) => (StatusCode::CREATED, Json(json!({ "id": id }))).into_response(),
Ok(id) => (
StatusCode::CREATED,
[(
header::LOCATION,
HeaderValue::from_str(id.to_string().as_str()).unwrap(),
)],
Json(json!({ "id": id })),
)
.into_response(),
Err(err) => {
tracing::error!("{}", err);
(
Expand Down

0 comments on commit 03062d4

Please sign in to comment.