Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Change log

### Version: 1.3.4
#### Date: Dec-19-2024
- Fix: Prevent baseURL concatenation when absolute URLs (http:// or https://) are passed to getData() or created by live preview, preventing malformed URLs

### Version: 1.3.3
#### Date: Nov-10-2025
- Fix: Added 'exports' field to package.json to fix ESM import error where '@contentstack/core' does not provide an export named 'getData' in modern ESM environments (e.g., Nuxt.js, Vite)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/core",
"version": "1.3.3",
"version": "1.3.4",
"type": "commonjs",
"main": "./dist/cjs/src/index.js",
"types": "./dist/cjs/src/index.d.ts",
Expand Down
16 changes: 13 additions & 3 deletions src/lib/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,31 @@ import { APIError } from './api-error';
*/
function serializeParams(params: any): string {
if (!params) return '';

return serialize(params);
}

/**
* Builds the full URL with query parameters
*/
function buildFullUrl(baseURL: string | undefined, url: string, queryString: string): string {
if (url.startsWith('http://') || url.startsWith('https://')) {
return `${url}?${queryString}`;
}
const base = baseURL || '';

return `${base}${url}?${queryString}`;
}

/**
* Makes the HTTP request with proper URL handling
*/
async function makeRequest(instance: AxiosInstance, url: string, requestConfig: any, actualFullUrl: string): Promise<any> {
async function makeRequest(
instance: AxiosInstance,
url: string,
requestConfig: any,
actualFullUrl: string
): Promise<any> {
// If URL is too long, use direct axios request with full URL
if (actualFullUrl.length > 2000) {
return await instance.request({
Expand Down Expand Up @@ -69,11 +79,11 @@ export async function getData(instance: AxiosInstance, url: string, data?: any)
}
}
}

const requestConfig = {
...data,
maxContentLength: Infinity,
maxBodyLength: Infinity
maxBodyLength: Infinity,
};
const queryString = serializeParams(requestConfig.params);
const actualFullUrl = buildFullUrl(instance.defaults.baseURL, url, queryString);
Expand Down
Loading
Loading