@dbs-portal/core-api
Version:
HTTP client and API utilities for DBS Portal
40 lines • 1.25 kB
JavaScript
/**
* Helper utilities for MSW testing in Node.js environment
* This file helps ensure that MSW correctly intercepts network requests
*/
/**
* Standard headers to include in all fetch requests to ensure MSW intercepts them
* The 'X-MSW-Bypass: no' header helps MSW with localhost resolution issues
*/
export const MSW_HEADERS = {
'X-MSW-Bypass': 'no'
};
/**
* Create headers with MSW interception support
* @param additionalHeaders Additional headers to include in the request
* @returns Headers object with MSW interception support
*/
export function createMSWHeaders(additionalHeaders = {}) {
return {
...MSW_HEADERS,
...additionalHeaders
};
}
/**
* Base URL for API requests
*/
export const API_BASE_URL = 'http://localhost:3000';
/**
* Create full URL for API requests
* @param path Path to API endpoint (with or without leading slash)
* @returns Full URL with API base
*/
export function createApiUrl(path) {
// If path already has protocol, return as is
if (path.startsWith('http'))
return path;
// Ensure path starts with slash
const normalizedPath = path.startsWith('/') ? path : `/${path}`;
return `${API_BASE_URL}${normalizedPath}`;
}
//# sourceMappingURL=msw-utils.js.map