Skip to content

Commit 64d9a8e

Browse files
committed
[feat] 포스트 작성 기능
1 parent dbec029 commit 64d9a8e

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/domains/community/write/WriteSection.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,21 @@ function WriteSection({ setIsOpen }: Props) {
3131
const handleSubmit = async (e: React.FormEvent) => {
3232
e.preventDefault();
3333

34+
const payload = new FormData();
35+
const postJson = {
36+
title: formData.title,
37+
content: formData.content,
38+
categoryId: 1,
39+
};
40+
41+
const postBlob = new Blob([JSON.stringify(postJson)], { type: 'application/json' });
42+
payload.append('post', postBlob);
43+
3444
try {
3545
const res = await fetch(`${getApi}/posts`, {
3646
method: 'POST',
37-
headers: {
38-
'Content-Type': 'application/json; charset=UTF-8',
39-
},
40-
body: JSON.stringify({
41-
title: formData.title,
42-
content: formData.content,
43-
categoryName: formData.categoryName,
44-
}),
47+
credentials: 'include',
48+
body: payload,
4549
});
4650

4751
console.log('▶ 요청 보낸 후 status:', res.status);

0 commit comments

Comments
 (0)