Skip to content

Commit 2b2845d

Browse files
Merge pull request #160 from contentstack/main
back merge
2 parents 5691607 + 3f1a289 commit 2b2845d

File tree

4 files changed

+202
-33
lines changed

4 files changed

+202
-33
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Change log
22

3+
### Version: 1.3.4
4+
#### Date: Nov-26-2025
5+
- Fix: Prevent baseURL concatenation when absolute URLs (http:// or https://) are passed to getData() or created by live preview, preventing malformed URLs
6+
37
### Version: 1.3.3
48
#### Date: Nov-10-2025
59
- 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)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/core",
3-
"version": "1.3.3",
3+
"version": "1.3.4",
44
"type": "commonjs",
55
"main": "./dist/cjs/src/index.js",
66
"types": "./dist/cjs/src/index.d.ts",

src/lib/request.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,31 @@ import { APIError } from './api-error';
88
*/
99
function serializeParams(params: any): string {
1010
if (!params) return '';
11+
1112
return serialize(params);
1213
}
1314

1415
/**
1516
* Builds the full URL with query parameters
1617
*/
1718
function buildFullUrl(baseURL: string | undefined, url: string, queryString: string): string {
19+
if (url.startsWith('http://') || url.startsWith('https://')) {
20+
return `${url}?${queryString}`;
21+
}
1822
const base = baseURL || '';
23+
1924
return `${base}${url}?${queryString}`;
2025
}
2126

2227
/**
2328
* Makes the HTTP request with proper URL handling
2429
*/
25-
async function makeRequest(instance: AxiosInstance, url: string, requestConfig: any, actualFullUrl: string): Promise<any> {
30+
async function makeRequest(
31+
instance: AxiosInstance,
32+
url: string,
33+
requestConfig: any,
34+
actualFullUrl: string
35+
): Promise<any> {
2636
// If URL is too long, use direct axios request with full URL
2737
if (actualFullUrl.length > 2000) {
2838
return await instance.request({
@@ -69,11 +79,11 @@ export async function getData(instance: AxiosInstance, url: string, data?: any)
6979
}
7080
}
7181
}
72-
82+
7383
const requestConfig = {
7484
...data,
7585
maxContentLength: Infinity,
76-
maxBodyLength: Infinity
86+
maxBodyLength: Infinity,
7787
};
7888
const queryString = serializeParams(requestConfig.params);
7989
const actualFullUrl = buildFullUrl(instance.defaults.baseURL, url, queryString);

0 commit comments

Comments
 (0)