Skip to content

Commit 78507a3

Browse files
authored
Merge pull request #47 from contentstack/feat/Live-Preview-Implementation
Feat/live preview implementation
2 parents e51d97e + bc6e83d commit 78507a3

File tree

6 files changed

+47
-21
lines changed

6 files changed

+47
-21
lines changed

.talismanrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
fileignoreconfig:
22
- filename: package-lock.json
3-
checksum: 31acb062f1514b4e9fb8604aca11b3db3da754befe51c969c788c460ed8c390f
3+
checksum: ebafc1a55b01b2259dacb35e2c286ad88c811974c6955d379be3205abbf1c7ff
44
version: ""

CHANGELOG.md

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

3+
### Version: 1.1.0
4+
#### Date: Aug-07-2024
5+
- Live Preview configuration changes
36

47
### Version: 1.0.3
58
#### Date: July-08-2024

package-lock.json

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/core",
3-
"version": "1.0.3",
3+
"version": "1.1.0",
44
"type": "commonjs",
55
"main": "./dist/cjs/src/index.js",
66
"types": "./dist/cjs/src/index.d.ts",
@@ -18,11 +18,11 @@
1818
"build:types": "node tools/cleanup types && tsc -p config/tsconfig.types.json"
1919
},
2020
"dependencies": {
21-
"axios": "^1.6.8",
21+
"axios": "^1.7.2",
2222
"axios-mock-adapter": "^1.22.0",
2323
"lodash": "^4.17.21",
24-
"qs": "^6.12.1",
25-
"tslib": "^2.6.2"
24+
"qs": "^6.13.0",
25+
"tslib": "^2.6.3"
2626
},
2727
"files": [
2828
"dist/*",

src/lib/request.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
1-
import { Axios } from 'axios';
1+
import { AxiosInstance } from './types';
22

3-
export async function getData(instance: Axios, url: string, data?: any) {
3+
export async function getData(instance: AxiosInstance, url: string, data?: any) {
44
try {
5+
if (instance.stackConfig && instance.stackConfig.live_preview) {
6+
const livePreviewParams = instance.stackConfig.live_preview;
7+
8+
if (livePreviewParams.enable) {
9+
data.live_preview = livePreviewParams.live_preview || 'init';
10+
}
11+
12+
if (livePreviewParams.preview_token) {
13+
instance.defaults.headers.preview_token = livePreviewParams.preview_token;
14+
instance.defaults.headers.live_preview = livePreviewParams.live_preview;
15+
}
16+
17+
if (livePreviewParams.enable && livePreviewParams.live_preview && livePreviewParams.live_preview !== 'init') {
18+
// adds protocol so host is replaced and not appended
19+
if (livePreviewParams.host.split(0, 8) === 'https://') {
20+
instance.defaults.baseURL = livePreviewParams.host;
21+
} else {
22+
instance.defaults.baseURL = 'https://' + livePreviewParams.host;
23+
}
24+
}
25+
}
526
const response = await instance.get(url, { params: data });
27+
628
if (response && response.data) {
729
return response.data;
830
} else {

src/lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type DefaultOptions = AxiosRequestConfig & {
1212
export type AxiosInstance = OriginalAxiosInstance & {
1313
httpClientParams: HttpClientParams;
1414
defaults: DefaultOptions;
15+
stackConfig: any;
1516
};
1617

1718
/*

0 commit comments

Comments
 (0)