Skip to content

Commit e5531e2

Browse files
committed
Fixed port forwarding error
1 parent 90a5afd commit e5531e2

2 files changed

Lines changed: 31 additions & 9 deletions

File tree

backend/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,9 +572,9 @@ func main() {
572572
r.Use(gin.Recovery()) // パニックリカバリ
573573
// CORS設定 (必要に応じてカスタマイズ)
574574
r.Use(cors.New(cors.Config{
575-
AllowOrigins: []string{"http://localhost:5173"}, // フロントエンドのオリジン (Viteのデフォルトポート)
575+
AllowOrigins: []string{"http://localhost:5173", "http://localhost:3000"},
576576
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"},
577-
AllowHeaders: []string{"Origin", "Content-Type", "Accept", "Authorization", "X-User-ID"}, // X-User-ID を追加
577+
AllowHeaders: []string{"Origin", "Content-Type", "Accept", "Authorization", "X-User-ID"},
578578
ExposeHeaders: []string{"Content-Length"},
579579
AllowCredentials: true,
580580
MaxAge: 12 * time.Hour,

frontend/src/services/api.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import type { Complex, ComplexInput } from '../types/complex';
22

3-
// 仮のユーザーID (認証基盤実装時に置き換える)
43
const DUMMY_USER_ID = 'user-test-123';
5-
64
const API_BASE_URL = '/api/v1';
75

86
const getAuthHeaders = () => ({
97
'Content-Type': 'application/json',
108
'X-User-ID': DUMMY_USER_ID,
119
});
1210

13-
/* コンプレックス一覧取得 */
11+
/* Get all complexes */
1412
export const fetchComplexes = async (): Promise<Complex[]> => {
1513
const response = await fetch(`${API_BASE_URL}/complexes`, {
1614
headers: getAuthHeaders(),
@@ -19,18 +17,36 @@ export const fetchComplexes = async (): Promise<Complex[]> => {
1917
return response.json();
2018
};
2119

22-
/* 新しいコンプレックスを登録 */
20+
/* Create new complex */
2321
export const createComplex = async (data: ComplexInput): Promise<Complex> => {
2422
const response = await fetch(`${API_BASE_URL}/complexes`, {
2523
method: 'POST',
2624
headers: getAuthHeaders(),
2725
body: JSON.stringify(data),
2826
});
29-
if (!response.ok) throw new Error('Failed to create complex');
27+
if (!response.ok) {
28+
let errorDetails = '';
29+
try {
30+
const responseText = await response.text();
31+
if (responseText) {
32+
try {
33+
const jsonData = JSON.parse(responseText);
34+
errorDetails = `: ${JSON.stringify(jsonData)}`;
35+
} catch (jsonError) {
36+
errorDetails = `: ${responseText}`;
37+
}
38+
}
39+
} catch (readError) {
40+
errorDetails = ': Failed to read error response body';
41+
}
42+
throw new Error(
43+
`Failed to create complex (status: ${response.status})${errorDetails}`
44+
);
45+
}
3046
return response.json();
3147
};
3248

33-
// コンプレックス削除 (ComplexesPage.tsxで使用していたダミー関数を置き換え)
49+
/* Delete complex */
3450
export const deleteComplex = async (id: number): Promise<void> => {
3551
const response = await fetch(`${API_BASE_URL}/complexes/${id}`, {
3652
method: 'DELETE',
@@ -39,4 +55,10 @@ export const deleteComplex = async (id: number): Promise<void> => {
3955
if (!response.ok) throw new Error('Failed to delete complex');
4056
};
4157

42-
// TODO: 他のAPI関数 (fetchComplex, updateComplex, fetchGoals, createGoalなど) もここに追加
58+
/*
59+
* TODO: 他のAPI関数もここに追加
60+
* - fetchComplex
61+
* - updateComplex
62+
* - fetchGoals
63+
* - createGoal
64+
*/

0 commit comments

Comments
 (0)