Skip to content

Commit

Permalink
Merge pull request #304 from GiganticMinecraft/feat/addResponseHeader…
Browse files Browse the repository at this point in the history
…ToformHandler

feat: フォーム作成のエントリポイントのレスポンスヘッダにLocationを含める
  • Loading branch information
rito528 authored Oct 22, 2023
2 parents 3923387 + 03062d4 commit a753126
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 @@ -86,7 +86,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,
Extension, Json,
};
Expand Down Expand Up @@ -29,7 +29,15 @@ pub async fn create_form_handler(
.create_form(form.title, form.description, user)
.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 a753126

Please sign in to comment.