Skip to content

Commit

Permalink
Merge pull request #95 from givery-bootcamp/bug-fix/delete-post
Browse files Browse the repository at this point in the history
bug-fix: 204のリクエストをzodios使って叩くとダメだということがわかったので、fetchに変えた
  • Loading branch information
shunsuke-tamura authored Jun 28, 2024
2 parents 281e804 + 78d36f8 commit 45a6992
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
3 changes: 2 additions & 1 deletion frontend/app/apiClient/apiClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createApiClient } from "./output.generated";

export const API_BASE_URL = process.env.API_BASE_URL ?? "http://localhost:4010";
// export const API_BASE_URL = process.env.API_BASE_URL ?? "http://localhost:4010";
export const API_BASE_URL = process.env.API_BASE_URL ?? "http://localhost:9000";

const apiClient = createApiClient(API_BASE_URL, {});

Expand Down
13 changes: 5 additions & 8 deletions frontend/app/routes/posts.$postId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import classNames from "classnames";
import { useState } from "react";
import formatDate from "utils/formatDate";
import apiClient from "~/apiClient/apiClient";
import apiClient, { API_BASE_URL } from "~/apiClient/apiClient";
import Button from "~/components/button";
import { useDialog } from "~/components/dialog";
import Observable from "~/components/observable";
Expand Down Expand Up @@ -71,19 +71,16 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
export async function action({ params, request }: ActionFunctionArgs) {
const postId = Number.parseInt(params.postId as string);
try {
await apiClient.deletePost(undefined, {
params: {
postId,
},
await fetch(`${API_BASE_URL}/posts/${postId}`, {
method: "DELETE",
headers: {
Cookie: request.headers.get("Cookie") as string,
},
});
return redirect("/");
} catch (e) {
return new Response((e as Error).message, {
status: 400,
});
console.error(e);
throw new Response(JSON.stringify(e), { status: 500 });
}
}

Expand Down

0 comments on commit 45a6992

Please sign in to comment.