From 03062d48396cf94edcb470e6cd838442a7dabe70 Mon Sep 17 00:00:00 2001 From: rito528 <39003544+rito528@users.noreply.github.com> Date: Sat, 14 Oct 2023 02:07:45 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=95=E3=82=A9=E3=83=BC=E3=83=A0?= =?UTF-8?q?=E4=BD=9C=E6=88=90=E3=81=AE=E3=82=A8=E3=83=B3=E3=83=88=E3=83=AA?= =?UTF-8?q?=E3=83=9D=E3=82=A4=E3=83=B3=E3=83=88=E3=81=AE=E3=83=AC=E3=82=B9?= =?UTF-8?q?=E3=83=9D=E3=83=B3=E3=82=B9=E3=83=98=E3=83=83=E3=83=80=E3=81=AB?= =?UTF-8?q?Location=E3=82=92=E5=90=AB=E3=82=81=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/entrypoint/src/main.rs | 5 +++-- server/presentation/src/form_handler.rs | 12 ++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/server/entrypoint/src/main.rs b/server/entrypoint/src/main.rs index ef08f8b5..bbb22023 100644 --- a/server/entrypoint/src/main.rs +++ b/server/entrypoint/src/main.rs @@ -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::{ @@ -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())); diff --git a/server/presentation/src/form_handler.rs b/server/presentation/src/form_handler.rs index f058db93..2848f321 100644 --- a/server/presentation/src/form_handler.rs +++ b/server/presentation/src/form_handler.rs @@ -1,6 +1,6 @@ use axum::{ extract::{Path, Query, State}, - http::StatusCode, + http::{header, HeaderValue, StatusCode}, response::IntoResponse, Json, }; @@ -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); (