Skip to content

Commit 9eb4adf

Browse files
authored
Merge pull request #93 from contentstack/feat/MKT-4708-lp-support
Feat/mkt 4708 lp support
2 parents 360ccac + 3c2d012 commit 9eb4adf

File tree

8 files changed

+257
-258
lines changed

8 files changed

+257
-258
lines changed

.env.local.sample

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,29 @@
22
#create environment file name as .env.local
33
#and place following configuration data.
44

5-
CONTENTSTACK_API_KEY=YOUR_API_KEY
6-
CONTENTSTACK_DELIVERY_TOKEN=YOUR_DELIVERY_TOKEN
7-
CONTENTSTACK_ENVIRONMENT=YOUR_PUBLISHING_ENVIRONMENT
5+
CONTENTSTACK_API_KEY=your_stack_api_key
6+
CONTENTSTACK_DELIVERY_TOKEN=your_delivery_token
7+
CONTENTSTACK_ENVIRONMENT=your_environment_token
88

9-
# For live preview
10-
CONTENTSTACK_MANAGEMENT_TOKEN=
11-
CONTENTSTACK_API_HOST=api.contentstack.io
9+
# Below config options are for enabling live preview/live edit tags for the starter app
10+
11+
CONTENTSTACK_PREVIEW_HOST= rest-preview.contentstack.com
12+
CONTENTSTACK_PREVIEW_TOKEN= your_live_preview_token
1213
CONTENTSTACK_APP_HOST=app.contentstack.com
13-
CONTENTSTACK_LIVE_PREVIEW=true
14-
CONTENTSTACK_LIVE_EDIT_TAGS=false
14+
CONTENTSTACK_LIVE_PREVIEW= true
15+
CONTENTSTACK_LIVE_EDIT_TAGS= false
1516

1617
#site-map
1718
NEXT_PUBLIC_HOSTED_URL=http://localhost:3000
18-
# Requires host url for sitemap. Localhost:3000 is set as default value
1919

20-
# For Live preview default value is to true to disable live preview set CONTENTSTACK_LIVE_PREVIEW=false
21-
# For live edit tags default value is set to false to enable live edit tag set CONTENTSTACK_LIVE_EDIT_TAGS=true
22-
# For NA region add CONTENTSTACK_APP_HOST=app.contentstack.com
23-
# For EU region add CONTENTSTACK_APP_HOST=eu-app.contentstack.com
20+
# CONTENTSTACK_API_HOST=api.contentstack.com
21+
# CONTENTSTACK_REGION=eu
22+
# CONTENTSTACK_BRANCH=main
2423

25-
# For setting custom host add CONTENTSTACK_API_HOST=for(NA: api.contentstack.io, EU: eu-api.contentstack.com)
24+
### NOTE:
25+
# CONTENTSTACK_API_HOST- For setting custom api host for contentstack sdk
26+
# CONTENTSTACK_REGION- For setting custom region for contentstack sdk default is us
27+
# CONTENTSTACK_BRANCH- For setting custom branch for contentstack sdk default is main
2628

27-
# For setting branch add CONTENTSTACK_BRANCH=(Optional for default branch(main)) Eg- develop
28-
# For setting region add CONTENTSTACK_REGION=(Optional for US region) Eg- eu
29+
# Setting Live Preview URL's
30+
# CONTENTSTACK_PREVIEW_HOST- For eu region use eu-rest-preview.contentstack.com/azure-na-rest-preview.contentstack.com/azure-eu-rest-preview.contentstack.com

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
timeout=60000

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Contentstack
3+
Copyright (c) 2024 Contentstack
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

contentstack-sdk/index.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,22 @@ const envConfig = process.env.CONTENTSTACK_API_KEY
2626
: publicRuntimeConfig;
2727

2828
let customHostBaseUrl = envConfig.CONTENTSTACK_API_HOST as string;
29-
customHostBaseUrl = customHostUrl(customHostBaseUrl);
29+
30+
customHostBaseUrl = customHostBaseUrl? customHostUrl(customHostBaseUrl): '';
3031

3132
// SDK initialization
3233
const Stack = initializeContentStackSdk();
3334

3435
// set host url only for custom host or non prod base url's
35-
if (isValidCustomHostUrl(customHostBaseUrl)) {
36+
if (!!customHostBaseUrl && isValidCustomHostUrl(customHostBaseUrl)) {
3637
Stack.setHost(customHostBaseUrl);
3738
}
3839

3940
// Setting LP if enabled
4041
ContentstackLivePreview.init({
4142
//@ts-ignore
4243
stackSdk: Stack,
43-
clientUrlParams: {
44-
host: envConfig.CONTENTSTACK_APP_HOST,
45-
},
46-
stackDetails: {
47-
apiKey: envConfig.CONTENTSTACK_API_KEY,
48-
environment: envConfig.CONTENTSTACK_ENVIRONMENT,
49-
},
50-
enable: envConfig.CONTENTSTACK_LIVE_PREVIEW === "true",
51-
ssr: false,
44+
ssr:false,
5245
})?.catch((err) => console.error(err));
5346

5447
export const { onEntryChange } = ContentstackLivePreview;

contentstack-sdk/utils.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const {
1010
CONTENTSTACK_ENVIRONMENT,
1111
CONTENTSTACK_BRANCH,
1212
CONTENTSTACK_REGION,
13-
CONTENTSTACK_MANAGEMENT_TOKEN,
14-
CONTENTSTACK_API_HOST,
13+
CONTENTSTACK_PREVIEW_TOKEN,
14+
CONTENTSTACK_PREVIEW_HOST,
1515
CONTENTSTACK_APP_HOST,
1616
CONTENTSTACK_LIVE_PREVIEW,
1717
} = envConfig;
@@ -28,8 +28,8 @@ export const isBasicConfigValid = () => {
2828
export const isLpConfigValid = () => {
2929
return (
3030
!!CONTENTSTACK_LIVE_PREVIEW &&
31-
!!CONTENTSTACK_MANAGEMENT_TOKEN &&
32-
!!CONTENTSTACK_API_HOST &&
31+
!!CONTENTSTACK_PREVIEW_TOKEN &&
32+
!!CONTENTSTACK_PREVIEW_HOST &&
3333
!!CONTENTSTACK_APP_HOST
3434
);
3535
};
@@ -49,9 +49,9 @@ const setLivePreviewConfig = (): LivePreview => {
4949
if (!isLpConfigValid())
5050
throw new Error("Your LP config is set to true. Please make you have set all required LP config in .env");
5151
return {
52-
management_token: CONTENTSTACK_MANAGEMENT_TOKEN as string,
52+
preview_token: CONTENTSTACK_PREVIEW_TOKEN as string,
5353
enable: CONTENTSTACK_LIVE_PREVIEW === "true",
54-
host: CONTENTSTACK_API_HOST as string,
54+
host: CONTENTSTACK_PREVIEW_HOST as string,
5555
} as LivePreview;
5656
};
5757
// contentstack sdk initialization
@@ -84,6 +84,6 @@ export const generateUrlBasedOnRegion = (): string[] => {
8484
});
8585
};
8686
// prod url validation for custom host
87-
export const isValidCustomHostUrl = (url: string): boolean => {
87+
export const isValidCustomHostUrl = (url=''): boolean => {
8888
return url ? !generateUrlBasedOnRegion().includes(url) : false;
8989
};

next.config.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
const withPWA = require('next-pwa')({
2-
dest: 'public'
1+
const withPWA = require("next-pwa")({
2+
dest: "public",
33
});
44

55
const config = {
66
publicRuntimeConfig: {
77
// Will be available on both server and client
88
CONTENTSTACK_API_KEY: process.env.CONTENTSTACK_API_KEY,
99
CONTENTSTACK_DELIVERY_TOKEN: process.env.CONTENTSTACK_DELIVERY_TOKEN,
10-
CONTENTSTACK_BRANCH: process.env.CONTENTSTACK_BRANCH || 'main',
11-
CONTENTSTACK_REGION:process.env.CONTENTSTACK_REGION || "us",
10+
CONTENTSTACK_BRANCH: process.env.CONTENTSTACK_BRANCH || "main",
11+
CONTENTSTACK_REGION: process.env.CONTENTSTACK_REGION || "us",
1212
CONTENTSTACK_ENVIRONMENT: process.env.CONTENTSTACK_ENVIRONMENT,
13-
CONTENTSTACK_MANAGEMENT_TOKEN: process.env.CONTENTSTACK_MANAGEMENT_TOKEN,
13+
CONTENTSTACK_PREVIEW_TOKEN: process.env.CONTENTSTACK_PREVIEW_TOKEN,
14+
CONTENTSTACK_PREVIEW_HOST:
15+
process.env.CONTENTSTACK_PREVIEW_HOST || "rest-preview.contentstack.com",
1416
CONTENTSTACK_API_HOST:
15-
process.env.CONTENTSTACK_API_HOST || 'api.contentstack.io',
17+
process.env.CONTENTSTACK_API_HOST || "api.contentstack.io",
1618
CONTENTSTACK_APP_HOST:
17-
process.env.CONTENTSTACK_APP_HOST || 'app.contentstack.com',
18-
CONTENTSTACK_LIVE_PREVIEW:
19-
process.env.CONTENTSTACK_LIVE_PREVIEW || 'true',
19+
process.env.CONTENTSTACK_APP_HOST || "app.contentstack.com",
20+
CONTENTSTACK_LIVE_PREVIEW: process.env.CONTENTSTACK_LIVE_PREVIEW || "true",
2021
CONTENTSTACK_LIVE_EDIT_TAGS:
21-
process.env.CONTENTSTACK_LIVE_EDIT_TAGS || 'false',
22+
process.env.CONTENTSTACK_LIVE_EDIT_TAGS || "false",
2223
},
24+
experimental: { largePageDataBytes: 128 * 100000 },
2325
};
2426
module.exports =
25-
process.env.NODE_ENV === 'development' ? config : withPWA(config);
27+
process.env.NODE_ENV === "development" ? config : withPWA(config);

0 commit comments

Comments
 (0)