Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 15 additions & 6 deletions lib/contentstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import { Page } from "./types";
import { getContentstackEndpoints, getRegionForString } from "@timbenniks/contentstack-endpoints";

// Set the region by string value from environment variables
const region = getRegionForString(process.env.NEXT_PUBLIC_CONTENTSTACK_REGION || "EU");

const region = getRegionForString(process.env.NEXT_PUBLIC_CONTENTSTACK_REGION as string)
// object with all endpoints for region.
const endpoints = getContentstackEndpoints(region, true)

Expand All @@ -26,8 +25,15 @@ export const stack = contentstack.stack({
// Setting the environment based on environment variables
environment: process.env.NEXT_PUBLIC_CONTENTSTACK_ENVIRONMENT as string,

// Setting the region based on environment variables
region: region,
// Setting the region
// if the region doesnt exist, fall back to a custom region given by the env vars
// for internal testing purposes at Contentstack we look for a custom region in the env vars, you do not have to do this.
region: region ? region : process.env.NEXT_PUBLIC_CONTENTSTACK_REGION as any,

// Setting the host for content delivery based on the region or environment variables
// This is done for internal testing purposes at Contentstack, you can omit this if you have set a region above.
host: process.env.NEXT_PUBLIC_CONTENTSTACK_CONTENT_DELIVERY || endpoints && endpoints.contentDelivery,

live_preview: {
// Enabling live preview if specified in environment variables
enable: process.env.NEXT_PUBLIC_CONTENTSTACK_PREVIEW === 'true',
Expand All @@ -36,7 +42,8 @@ export const stack = contentstack.stack({
preview_token: process.env.NEXT_PUBLIC_CONTENTSTACK_PREVIEW_TOKEN,

// Setting the host for live preview based on the region
host: endpoints.preview,
// for internal testing purposes at Contentstack we look for a custom host in the env vars, you do not have to do this.
host: process.env.NEXT_PUBLIC_CONTENTSTACK_PREVIEW_HOST || endpoints && endpoints.preview
}
});

Expand All @@ -52,7 +59,9 @@ export function initLivePreview() {
environment: process.env.NEXT_PUBLIC_CONTENTSTACK_ENVIRONMENT as string, // Setting the environment from environment variables
},
clientUrlParams: {
host: endpoints.application
// Setting the client URL parameters for live preview
// for internal testing purposes at Contentstack we look for a custom host in the env vars, you do not have to do this.
host: process.env.NEXT_PUBLIC_CONTENTSTACK_CONTENT_APPLICATION || endpoints && endpoints.application
},
editButton: {
enable: true, // Enabling the edit button for live preview
Expand Down
14 changes: 7 additions & 7 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
// Configure allowed hostnames for Next.js Image Optimization
remotePatterns: [
{
hostname: "images.contentstack.io",
},
{
protocol: "https",
hostname: "*-images.contentstack.com",
},
...(process.env.NEXT_PUBLIC_CONTENTSTACK_IMAGE_HOSTNAME
? [{ hostname: process.env.NEXT_PUBLIC_CONTENTSTACK_IMAGE_HOSTNAME }]
: [
{ hostname: "images.contentstack.io" },
{ hostname: "*-images.contentstack.com" },
]),
],
},
};
Expand Down
128 changes: 64 additions & 64 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
},
"dependencies": {
"@contentstack/delivery-sdk": "^4.8.0",
"@contentstack/live-preview-utils": "^3.3.0",
"@timbenniks/contentstack-endpoints": "^1.0.12",
"@contentstack/live-preview-utils": "^3.4.0",
"@timbenniks/contentstack-endpoints": "^1.0.14",
"dompurify": "^3.2.6",
"next": "^15.4.5",
"next": "^15.4.6",
"react": "^19.1.1",
"react-dom": "^19.1.1"
},
"devDependencies": {
"@tailwindcss/postcss": "^4.1.11",
"@types/node": "^24.1.0",
"@types/node": "^24.2.0",
"@types/react": "^19.1.9",
"@types/react-dom": "^19.1.7",
"eslint": "^9.32.0",
"eslint-config-next": "^15.4.5",
"eslint-config-next": "^15.4.6",
"postcss": "^8.5.6",
"tailwindcss": "^4.1.11",
"typescript": "^5.9.2"
Expand Down