Skip to content

Commit 59622b6

Browse files
committed
Fixed API key not parsing in request headers
1 parent f8004bf commit 59622b6

1 file changed

Lines changed: 27 additions & 19 deletions

File tree

dashboard/src/services/api.ts

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,34 @@ import {
1818
} from '@/types/state-manager';
1919

2020
const API_BASE_URL = process.env.NEXT_PUBLIC_EXOSPHERE_STATE_MANAGER_URL || 'http://localhost:8000';
21-
21+
const DEFAULT_API_KEY = process.env.NEXT_PUBLIC_EXOSPHERE_API_KEY || '';
2222
class ApiService {
2323
private async makeRequest<T>(
2424
endpoint: string,
2525
options: RequestInit = {}
2626
): Promise<T> {
2727
const url = `${API_BASE_URL}${endpoint}`;
2828

29+
const headers = new Headers(options.headers);
30+
headers.set('Content-Type', 'application/json');
31+
headers.set('x-api-key', process.env.NEXT_PUBLIC_EXOSPHERE_API_KEY || '');
32+
2933
const response = await fetch(url, {
30-
headers: {
31-
'Content-Type': 'application/json',
32-
...options.headers,
33-
},
3434
...options,
35+
headers,
3536
});
36-
37+
3738
if (!response.ok) {
38-
throw new Error(`API request failed: ${response.status} ${response.statusText}`);
39+
const errorData = await response.json().catch(() => ({}));
40+
console.error('API Error:', {
41+
status: response.status,
42+
statusText: response.statusText,
43+
url,
44+
errorData
45+
});
46+
throw new Error(errorData.detail || `API request failed: ${response.statusText}`);
3947
}
40-
48+
4149
return response.json();
4250
}
4351

@@ -52,7 +60,7 @@ class ApiService {
5260
{
5361
method: 'PUT',
5462
headers: {
55-
'X-API-Key': apiKey,
63+
'X-API-Key': DEFAULT_API_KEY,
5664
},
5765
body: JSON.stringify(request),
5866
}
@@ -88,7 +96,7 @@ class ApiService {
8896
{
8997
method: 'GET',
9098
headers: {
91-
'X-API-Key': apiKey,
99+
'X-API-Key': DEFAULT_API_KEY,
92100
},
93101
}
94102
);
@@ -106,7 +114,7 @@ class ApiService {
106114
{
107115
method: 'POST',
108116
headers: {
109-
'X-API-Key': apiKey,
117+
'X-API-Key': DEFAULT_API_KEY,
110118
},
111119
body: JSON.stringify(request),
112120
}
@@ -123,7 +131,7 @@ class ApiService {
123131
{
124132
method: 'POST',
125133
headers: {
126-
'X-API-Key': apiKey,
134+
'X-API-Key': DEFAULT_API_KEY,
127135
},
128136
body: JSON.stringify(request),
129137
}
@@ -141,7 +149,7 @@ class ApiService {
141149
{
142150
method: 'POST',
143151
headers: {
144-
'X-API-Key': apiKey,
152+
'X-API-Key': DEFAULT_API_KEY,
145153
},
146154
body: JSON.stringify(request),
147155
}
@@ -158,7 +166,7 @@ class ApiService {
158166
{
159167
method: 'GET',
160168
headers: {
161-
'X-API-Key': apiKey,
169+
'X-API-Key': DEFAULT_API_KEY,
162170
},
163171
}
164172
);
@@ -174,7 +182,7 @@ class ApiService {
174182
{
175183
method: 'GET',
176184
headers: {
177-
'X-API-Key': apiKey,
185+
'X-API-Key': DEFAULT_API_KEY,
178186
},
179187
}
180188
);
@@ -189,7 +197,7 @@ class ApiService {
189197
{
190198
method: 'GET',
191199
headers: {
192-
'X-API-Key': apiKey,
200+
'X-API-Key': DEFAULT_API_KEY,
193201
},
194202
}
195203
);
@@ -205,7 +213,7 @@ class ApiService {
205213
{
206214
method: 'GET',
207215
headers: {
208-
'X-API-Key': apiKey,
216+
'X-API-Key': DEFAULT_API_KEY,
209217
},
210218
}
211219
);
@@ -221,7 +229,7 @@ class ApiService {
221229
{
222230
method: 'GET',
223231
headers: {
224-
'X-API-Key': apiKey,
232+
'X-API-Key': DEFAULT_API_KEY,
225233
},
226234
}
227235
);
@@ -237,7 +245,7 @@ class ApiService {
237245
{
238246
method: 'GET',
239247
headers: {
240-
'X-API-Key': apiKey,
248+
'X-API-Key': DEFAULT_API_KEY,
241249
},
242250
}
243251
);

0 commit comments

Comments
 (0)