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
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ NEXT_PUBLIC_CONTENTSTACK_API_KEY=your_api_key_here
NEXT_PUBLIC_CONTENTSTACK_DELIVERY_TOKEN=your_delivery_token_here
NEXT_PUBLIC_CONTENTSTACK_PREVIEW_TOKEN=your_preview_token_here
NEXT_PUBLIC_CONTENTSTACK_ENVIRONMENT=preview
NEXT_PUBLIC_CONTENTSTACK_REGION=EU # Options: EU or NA
NEXT_PUBLIC_CONTENTSTACK_REGION=EU # Options: NA, EU, AU, AZURE-NA, AZURE-EU, GCP-NA, GCP-EU
NEXT_PUBLIC_CONTENTSTACK_PREVIEW=true # Set to true to enable preview
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ To use: Open any entry in Contentstack → Click Live Preview → Edit and see c

- **Dynamic Components**: `ComponentsRenderer` maps Contentstack modular blocks to React components
- **Type-Safe Fetching**: TypeScript interfaces for all content types with React Cache
- **Region-Specific SDK**: Configured for EU region with automatic endpoint resolution
- **Region-Specific SDK**: Automatic endpoint resolution via `getContentstackEndpoint` from `@contentstack/utils` — supports all 7 Contentstack regions
- **CSLP Integration**: Components receive `$` prop with editable tags for Live Preview
- **Catch-All Routing**: `[[...slug]]` handles all dynamic pages with ISR (30-min revalidation)
- **Unified Data Fetching**: `pageUtils.ts` provides consistent data fetching across all page types
Expand Down Expand Up @@ -219,3 +219,45 @@ MIT License - see [LICENSE](https://github.com/contentstack/kickstart-veda/blob/
---

**Built with ❤️ by Contentstack**

---

## Regions and endpoint configuration

Set `NEXT_PUBLIC_CONTENTSTACK_REGION` to the value matching your Contentstack account region:

| Region | Value |
|---|---|
| North America (default) | `NA` or `US` |
| Europe | `EU` |
| Australia | `AU` |
| Azure North America | `AZURE-NA` |
| Azure Europe | `AZURE-EU` |
| GCP North America | `GCP-NA` |
| GCP Europe | `GCP-EU` |

The app uses `getContentstackEndpoint` from `@contentstack/utils` to resolve the correct API hostnames for your region automatically. The following endpoint keys are resolved:

| Key | NA value |
|---|---|
| `contentDelivery` | `cdn.contentstack.io` |
| `preview` | `rest-preview.contentstack.com` |
| `application` | `app.contentstack.com` |
| `graphqlDelivery` | `graphql.contentstack.com` |
| `graphqlPreview` | `graphql-preview.contentstack.com` |
| `images` | `images.contentstack.io` |
| `assets` | `assets.contentstack.io` |
| `contentManagement` | `api.contentstack.io` |
| `auth` | `auth.contentstack.io` |

### Custom or dedicated environments

If you are on a dedicated or private cloud Contentstack instance, you can override the resolved endpoints via environment variables:

```
NEXT_PUBLIC_CONTENTSTACK_CONTENT_DELIVERY=your-custom-cdn.example.com
NEXT_PUBLIC_CONTENTSTACK_PREVIEW_HOST=your-custom-preview.example.com
NEXT_PUBLIC_CONTENTSTACK_CONTENT_APPLICATION=your-custom-app.example.com
```

These override values take precedence over the region-resolved endpoints.
16 changes: 9 additions & 7 deletions lib/contentstack.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import contentstack, { QueryOperation } from "@contentstack/delivery-sdk";
import ContentstackLivePreview, { IStackSdk } from "@contentstack/live-preview-utils";
import { Page, ProductLine, Header, MegaMenu, Category, Product } from "./types";
import { getContentstackEndpoints, getRegionForString } from "@timbenniks/contentstack-endpoints";
import { getContentstackEndpoint, type ContentstackEndpoints } from "@contentstack/utils";
import type { Metadata } from "next";
import type { EmbeddedItem } from '@contentstack/utils/dist/types/Models/embedded-object'

const region = getRegionForString(process.env.NEXT_PUBLIC_CONTENTSTACK_REGION as string)
const endpoints = getContentstackEndpoints(region, true)
const endpoints = getContentstackEndpoint(process.env.NEXT_PUBLIC_CONTENTSTACK_REGION || 'NA', '', true) as ContentstackEndpoints
export const isPreview = process.env.NEXT_PUBLIC_CONTENTSTACK_PREVIEW === "true";

export const stack = contentstack.stack({
apiKey: process.env.NEXT_PUBLIC_CONTENTSTACK_API_KEY as string,
deliveryToken: process.env.NEXT_PUBLIC_CONTENTSTACK_DELIVERY_TOKEN as string,
environment: process.env.NEXT_PUBLIC_CONTENTSTACK_ENVIRONMENT as string,
region: region ? region : process.env.NEXT_PUBLIC_CONTENTSTACK_REGION as any,
host: process.env.NEXT_PUBLIC_CONTENTSTACK_CONTENT_DELIVERY || endpoints && endpoints.contentDelivery,

// Certain API endpoints can be set via environment variables for custom or dedicated Contentstack environments.
// You can omit these in your project. Use @contentstack/utils getContentstackEndpoint to get the right urls for your region.
region: process.env.NEXT_PUBLIC_CONTENTSTACK_REGION as any,
host: process.env.NEXT_PUBLIC_CONTENTSTACK_CONTENT_DELIVERY || endpoints.contentDelivery as string,

live_preview: {
enable: process.env.NEXT_PUBLIC_CONTENTSTACK_PREVIEW === 'true',
preview_token: process.env.NEXT_PUBLIC_CONTENTSTACK_PREVIEW_TOKEN,
host: process.env.NEXT_PUBLIC_CONTENTSTACK_PREVIEW_HOST || endpoints && endpoints.preview
host: process.env.NEXT_PUBLIC_CONTENTSTACK_PREVIEW_HOST || endpoints.preview as string
}
});

Expand All @@ -34,7 +36,7 @@ export function initLivePreview() {
environment: process.env.NEXT_PUBLIC_CONTENTSTACK_ENVIRONMENT as string,
},
clientUrlParams: {
host: process.env.NEXT_PUBLIC_CONTENTSTACK_CONTENT_APPLICATION || endpoints && endpoints.application
host: process.env.NEXT_PUBLIC_CONTENTSTACK_CONTENT_APPLICATION || endpoints.application as string
},
editButton: {
enable: true,
Expand Down
Loading
Loading