Bugfix storybook now works with live API data or with built tests
This commit is contained in:
@@ -35,7 +35,7 @@ export const Populated = {
|
||||
msw: {
|
||||
handlers: [
|
||||
// Intercept the exact URL your component is trying to fetch
|
||||
http.get('*/api/v2/dvar_vaa', () => {
|
||||
http.get('*/api/v2/comm_coor_vaa', () => {
|
||||
// Return a 200 OK with the mock JSON
|
||||
return HttpResponse.json(mockData);
|
||||
}),
|
||||
@@ -49,7 +49,7 @@ export const ServerCrash = {
|
||||
parameters: {
|
||||
msw: {
|
||||
handlers: [
|
||||
http.get('*/api/v2/dvar_vaa', () => {
|
||||
http.get('*/api/v2/comm_coor_vaa', () => {
|
||||
// Return a 500 Error
|
||||
return new HttpResponse(null, { status: 500 });
|
||||
}),
|
||||
@@ -63,7 +63,7 @@ export const EmptyData = {
|
||||
parameters: {
|
||||
msw: {
|
||||
handlers: [
|
||||
http.get('*/api/v2/dvar_vaa', () => {
|
||||
http.get('*/api/v2/comm_coor_vaa', () => {
|
||||
return HttpResponse.json([]);
|
||||
}),
|
||||
],
|
||||
|
||||
@@ -11,10 +11,13 @@ export default function useWidgetApi(endpoint) {
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const baseUrl = import.meta.env.VITE_API_BASE_URL || 'http://web-api:8000';
|
||||
// Strip leading slashes to prevent double slashes in the URL
|
||||
const cleanEndpoint = endpoint.startsWith('/') ? endpoint.slice(1) : endpoint;
|
||||
const url = `${baseUrl}/${cleanEndpoint}`;
|
||||
// CHANGED: Fallback is now an empty string.
|
||||
const baseUrl = import.meta.env.VITE_API_BASE_URL || '';
|
||||
|
||||
// CHANGED: Ensure the endpoint always starts with a slash
|
||||
// so it resolves perfectly as a relative path to the root domain.
|
||||
const cleanEndpoint = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
|
||||
const url = `${baseUrl}${cleanEndpoint}`;
|
||||
|
||||
const response = await fetch(url);
|
||||
|
||||
@@ -37,7 +40,7 @@ export default function useWidgetApi(endpoint) {
|
||||
if (endpoint) {
|
||||
fetchData();
|
||||
}
|
||||
}, [endpoint]); // Re-fetch if the endpoint changes
|
||||
}, [endpoint]);
|
||||
|
||||
return { data, isLoading, error };
|
||||
}
|
||||
Reference in New Issue
Block a user