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 @@ NG_APP_CONTENTSTACK_API_KEY=your_api_key_here
NG_APP_CONTENTSTACK_DELIVERY_TOKEN=your_delivery_token_here
NG_APP_CONTENTSTACK_PREVIEW_TOKEN=your_preview_token_here
NG_APP_CONTENTSTACK_ENVIRONMENT=preview
NG_APP_CONTENTSTACK_REGION=EU
NG_APP_CONTENTSTACK_REGION=EU # Options: NA, EU, AU, AZURE-NA, AZURE-EU, GCP-NA, GCP-EU
NG_APP_CONTENTSTACK_PREVIEW=true
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,43 @@ Go to `http://localhost:4200/`.
Go to Entries and select the only entry in the list.
In the sidebar, click on the live preview icon.
Or, click on visual experience in the sidebar.

## Regions and endpoint configuration

Set `NG_APP_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 (via `generate-env.js` at build time). 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:

```
NG_APP_CONTENTSTACK_CONTENT_DELIVERY=your-custom-cdn.example.com
NG_APP_CONTENTSTACK_PREVIEW_HOST=your-custom-preview.example.com
NG_APP_CONTENTSTACK_CONTENT_APPLICATION=your-custom-app.example.com
```

These override values take precedence over the region-resolved endpoints.
42 changes: 10 additions & 32 deletions generate-env.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#!/usr/bin/env node

const {
getContentstackEndpoints,
getRegionForString,
} = require("@timbenniks/contentstack-endpoints");
const { getContentstackEndpoint } = require("@contentstack/utils");

const fs = require("fs");
const path = require("path");
Expand All @@ -30,8 +27,7 @@ if (fs.existsSync(envPath)) {
});
}

const region = getRegionForString(envVars.NG_APP_CONTENTSTACK_REGION);
const endpoints = getContentstackEndpoints(region, true);
const endpoints = getContentstackEndpoint(envVars.NG_APP_CONTENTSTACK_REGION || 'us', '', true);

// Generate environment.ts content
const environmentContent = `export const environment = {
Expand All @@ -41,21 +37,12 @@ const environmentContent = `export const environment = {
deliveryToken: '${envVars.NG_APP_CONTENTSTACK_DELIVERY_TOKEN || ""}',
previewToken: '${envVars.NG_APP_CONTENTSTACK_PREVIEW_TOKEN || ""}',
environment: '${envVars.NG_APP_CONTENTSTACK_ENVIRONMENT || "preview"}',
region: '${region ? region : envVars.NG_APP_CONTENTSTACK_REGION}',
region: '${envVars.NG_APP_CONTENTSTACK_REGION || "us"}',
preview: ${envVars.NG_APP_CONTENTSTACK_PREVIEW === "true"},

contentDelivery: '${
envVars.NG_APP_CONTENTSTACK_CONTENT_DELIVERY ||
(endpoints && endpoints.contentDelivery)
}',
previewHost: '${
envVars.NG_APP_CONTENTSTACK_PREVIEW_HOST ||
(endpoints && endpoints.preview)
}',
applicationHost: '${
envVars.NG_APP_CONTENTSTACK_CONTENT_APPLICATION ||
(endpoints && endpoints.application)
}'
contentDelivery: '${envVars.NG_APP_CONTENTSTACK_CONTENT_DELIVERY || endpoints.contentDelivery}',
previewHost: '${envVars.NG_APP_CONTENTSTACK_PREVIEW_HOST || endpoints.preview}',
applicationHost: '${envVars.NG_APP_CONTENTSTACK_CONTENT_APPLICATION || endpoints.application}'
}
};
`;
Expand All @@ -68,21 +55,12 @@ const environmentProdContent = `export const environment = {
deliveryToken: '${envVars.NG_APP_CONTENTSTACK_DELIVERY_TOKEN || ""}',
previewToken: '${envVars.NG_APP_CONTENTSTACK_PREVIEW_TOKEN || ""}',
environment: '${envVars.NG_APP_CONTENTSTACK_ENVIRONMENT || "preview"}',
region: '${region ? region : envVars.NG_APP_CONTENTSTACK_REGION}',
region: '${envVars.NG_APP_CONTENTSTACK_REGION || "us"}',
preview: ${envVars.NG_APP_CONTENTSTACK_PREVIEW === "true"},

contentDelivery: '${
envVars.NG_APP_CONTENTSTACK_CONTENT_DELIVERY ||
(endpoints && endpoints.contentDelivery)
}',
previewHost: '${
envVars.NG_APP_CONTENTSTACK_PREVIEW_HOST ||
(endpoints && endpoints.preview)
}',
applicationHost: '${
envVars.NG_APP_CONTENTSTACK_CONTENT_APPLICATION ||
(endpoints && endpoints.application)
}'
contentDelivery: '${envVars.NG_APP_CONTENTSTACK_CONTENT_DELIVERY || endpoints.contentDelivery}',
previewHost: '${envVars.NG_APP_CONTENTSTACK_PREVIEW_HOST || endpoints.preview}',
applicationHost: '${envVars.NG_APP_CONTENTSTACK_CONTENT_APPLICATION || endpoints.application}'

}
};
Expand Down
Loading
Loading