Skip to content

Add custom hostname support#359

Open
MenKNas wants to merge 24 commits intodevfrom
feature/JSS-7383-add-custom-hostname-support
Open

Add custom hostname support#359
MenKNas wants to merge 24 commits intodevfrom
feature/JSS-7383-add-custom-hostname-support

Conversation

@MenKNas
Copy link
Contributor

@MenKNas MenKNas commented Feb 2, 2026

Description / Motivation

Support custom Edge hostnames

This PR adds support for custom Sitecore Edge hostnames by resolving the Edge base URL from SITECORE_EDGE_PLATFORM_HOSTNAME (and, for Next.js, NEXT_PUBLIC_SITECORE_EDGE_PLATFORM_HOSTNAME) and ensuring SDK requests and layout/editing data can use the custom hostname instead of the default Edge Platform host. It also adds opt-in media URL rewriting so that URLs in layout data (e.g. image fields, rich text) can be rewritten to the custom hostname when desired.

How it works

  • Edge URL resolution: The Edge base URL is resolved once at config level (e.g. in define-config): explicit config value → SITECORE_EDGE_PLATFORM_HOSTNAME / Next.js public equivalent → default Edge Platform URL. Helpers receive the already-resolved URL and only normalize it; they do not read env or resolve again.
  • Custom hostname in responses: When a custom hostname is configured, layout/editing/component responses can be post-processed to replace embedded default Edge hostnames with the resolved custom hostname (default rewriter in rewrite-edge-host.ts).
  • Opt-in media rewrite: Media URL rewriting is off by default. When rewriteMediaUrls: true is set in Sitecore config, the client applies the default Edge host rewriter to layout data before returning it (rewriting media URLs and rich text to the custom hostname). When rewriteMediaUrls is a function, that function is used to transform each string in the layout.
  • Static files: resolveEdgeUrlForStaticFiles() always returns the default Edge Platform URL so that static assets (e.g. stylesheets under /v1/files/...) continue to load from the platform when the custom host does not serve them.
  • Custom rewriter: Apps can set rewriteMediaUrls to a custom (value: string) => string to implement their own URL transformation over layout strings.

Key files

  • packages/core/src/tools/resolve-edge-url.ts – Edge base URL resolution (used at config time); resolveEdgeUrlForStaticFiles() for static assets.
  • packages/content/src/layout/rewrite-edge-host.ts – Rewrites default Edge hostnames in layout/editing responses to the resolved custom hostname; used as the default when rewriteMediaUrls: true.
  • packages/content/src/config/define-config.ts – Resolves edge URL at config level; default rewriteMediaUrls: false.
  • packages/content/src/client/sitecore-client.ts – Applies the rewriteMediaUrls rewriter when enabled.

Testing Details

  • Unit Test Added
  • Manual Test/Other =>

Tested manually in sample app using custom hostname provided in https://portal-staging.sitecore-staging.cloud/admin/custom-hostnames?organization=org_Jk9RJbQPa0m9Psul (test3-staging.envoy-test.cloud)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

@github-actions
Copy link

github-actions bot commented Feb 2, 2026

📦 Package Size and Test Coverage Report

Package Base Size PR Size Δ Change Base Coverage PR Coverage Δ Change
analytics-core 122.52 KB 122.52 KB ✅ 0.00 KB 100.00% 100.00% 0.00%
cli 58.70 KB 58.70 KB ✅ 0.00 KB 69.73% 69.73% 0.00%
content 397.02 KB 416.74 KB 🔺 +19.72 KB 92.35% 92.02% -0.34%
core 90.85 KB 101.78 KB 🔺 +10.93 KB 91.82% 92.77% +0.95%
create-content-sdk-app 243.64 KB 244.73 KB 🔺 +1.09 KB 96.22% 96.22% 0.00%
events 76.91 KB 76.91 KB ✅ 0.00 KB 98.40% 98.40% 0.00%
nextjs 430.10 KB 431.20 KB 🔺 +1.10 KB 89.75% 89.78% +0.03%
personalize 63.45 KB 63.45 KB ✅ 0.00 KB 99.32% 99.32% 0.00%
react 289.54 KB 289.57 KB 🔺 +0.03 KB 93.80% 93.80% 0.00%
search 7.11 KB 7.30 KB 🔺 +0.19 KB 98.57% 98.57% 0.00%
Total 🔺 +33.06 KB

@MenKNas MenKNas marked this pull request as ready for review February 4, 2026 07:01
MenKNas and others added 4 commits February 10, 2026 18:36
…ession for hostnames

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…ession for hostnames

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Copy link
Collaborator

@illiakovalenko illiakovalenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my feedback and suggestions for improvement

*/
const DEFAULT_EDGE_HOSTNAMES = [
'edge-platform.sitecorecloud.io',
'edge.sitecorecloud.io', // Legacy hostname included for safety replacement
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a legacy URL - it is an Experience Edge URL.

We can leave default production url, but we cannot hardcode or enumerate custom environments here (staging, dev etc.). Customers and some internal teams may use additional environments, and with the current implementation they would not be able to configure custom hostnames.

To address this properly, we should introduce an internal environment variable: SITECORE_EXPERIENCE_EDGE_HOSTNAME. This variable would need to be populated by the Deploy team, allowing custom environment hostnames to be specified without constraining the implementation.

Copy link
Collaborator

@illiakovalenko illiakovalenko Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MenKNas This comment is not resolved, as no changes have been applied, except of moving to "core"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is applicable to local development with containers

* Available on both server and client (e.g. NEXT_PUBLIC_* in Next.js).
* @public
*/
export const SITECORE_EDGE_HOSTNAME_PUBLIC_ENV = 'NEXT_PUBLIC_SITECORE_EDGE_HOSTNAME';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refer to my previous comment where I pointed out that the core package should not reference Next.js–specific environment variables. This should instead be handled at the nextjs package level, for example via a defineConfig override. Also it's not renamed to "SITECORE_EDGE_PLATFORM_HOSTNAME"

export function getDesignLibraryScriptLink(sitecoreEdgeUrl = SITECORE_EDGE_URL_DEFAULT): string {
return `${normalizeUrl(sitecoreEdgeUrl)}/v1/files/designlibrary/lib/rh-lib-script.js`;
export function getDesignLibraryScriptLink(sitecoreEdgeUrl?: string): string {
return `${(sitecoreEdgeUrl ? normalizeUrl(sitecoreEdgeUrl) : resolveEdgeUrl())}/v1/files/designlibrary/lib/rh-lib-script.js`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refer to my earlier comment. The current approach still introduces unnecessary complexity without a clear justification.

As mentioned before, the edge URL should be resolved and normalized in a single place - at the configuration level. There is no need to repeat this logic every time the edge URL is passed as a parameter.

This applies to ALL occurrences

*/
const DEFAULT_EDGE_HOSTNAMES = [
'edge-platform.sitecorecloud.io',
'edge.sitecorecloud.io', // Legacy hostname included for safety replacement
Copy link
Collaborator

@illiakovalenko illiakovalenko Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MenKNas This comment is not resolved, as no changes have been applied, except of moving to "core"

@@ -4,6 +4,23 @@
*/
export const SITECORE_EDGE_URL_DEFAULT = 'https://edge-platform.sitecorecloud.io';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const SITECORE_EDGE_URL_DEFAULT = 'https://edge-platform.sitecorecloud.io';
export const SITECORE_EDGE_PLATFORM_URL_DEFAULT = 'https://edge-platform.sitecorecloud.io';


# Optional: custom Experience Edge hostname override (XM Cloud/Edge; hostname or full URL).
# Available on both server and client.
NEXT_PUBLIC_SITECORE_EDGE_HOSTNAME=
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
NEXT_PUBLIC_SITECORE_EDGE_HOSTNAME=
NEXT_PUBLIC_SITECORE_EDGE_PLATFORM_HOSTNAME=

# Will be used as a fallback if separate SITECORE_EDGE_CONTEXT_ID value is not provided
NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID=

# Optional: custom Experience Edge hostname override (XM Cloud/Edge; hostname or full URL).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Optional: custom Experience Edge hostname override (XM Cloud/Edge; hostname or full URL).
# Optional: custom Sitecore Edge Platform hostname (hostname or full URL).

NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID=

# Optional: custom Experience Edge hostname override (XM Cloud/Edge; hostname or full URL).
# Available on both server and client.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed, as it is already expected behavior for Next.js developers when using NEXT_PUBLIC environment variables.

Suggested change
# Available on both server and client.


# Optional: custom Experience Edge hostname override (XM Cloud/Edge; hostname or full URL).
# Available on both server and client.
NEXT_PUBLIC_SITECORE_EDGE_HOSTNAME=
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, see my comments for "nextjs" template as a references

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add unit tests

CHANGELOG.md Outdated
- Available in both Pages Router and App Router templates

* `[core]` `[content]` `[nextjs]` Support custom Edge hostnames via `NEXT_PUBLIC_SITECORE_EDGE_HOSTNAME` ([#359](https://github.com/Sitecore/content-sdk/pull/359))
- Consolidated `rewriteContentUrls` and `contentRewrite` into `rewriteMediaUrls: boolean | ((value: string) => string)`. When `true`, uses default Edge host rewriter; when a function, transforms each string (SDK traverses layout). Migration: `rewriteContentUrls: true` → `rewriteMediaUrls: true`; custom rewriter → `rewriteMediaUrls: (value: string) => string`
Copy link
Collaborator

@illiakovalenko illiakovalenko Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make sure to double check the AI-generated notes? It should be removed as it was renamed and consolidated during the PR review, initially we didn't have this feature.
We can simply mention the new property that was introduced

MenKNas and others added 4 commits February 17, 2026 13:02
Co-authored-by: Illia Kovalenko <23364749+illiakovalenko@users.noreply.github.com>
`${normalizeUrl(sitecoreEdgeUrl)}/v1/content/api/graphql/v1`;
export const getEdgeProxyContentUrl = (
sitecoreEdgeUrl: string = constants.SITECORE_EXPERIENCE_EDGE_URL_DEFAULT
) => `${getBaseEdgeUrl(sitecoreEdgeUrl)}/v1/content/api/graphql/v1`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me clarify again the difference between Experience Edge and Edge Platform URLs, as there appears to be a misunderstanding.

Experience Edge (https://edge.sitecorecloud.io)
– Used for media URLs.

Edge Platform (https://edge-platform.sitecorecloud.io)
– Used by our services to resolve endpoints.

Based on the changes you introduced, Experience Edge is now being referenced when resolving service endpoints. This is not correct. We should continue using the default Edge Platform URL for service-related requests.

The Experience Edge URL should be referenced only when replacing media URLs.
This is the only place where the Experience Edge URL environment variable should be used, in order to allow overriding it when necessary.


const contextId = serverContextId || clientContextId;
// Use default Edge URL for styles (ignore custom hostname) so stylesheets load from platform
const edgeUrlForStyles = resolveEdgeUrlForStaticFiles();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are stylesheets not supported with a custom hostname? Is this an existing limitation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using a custom hostname and attempting to serve styles, it resulted in a 404 error, and the styles on the page appeared broken. So I kept it this way to make sure styles don't break in this case.

NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID=

# Optional: custom Sitecore Edge Platform hostname (hostname or full URL).
# Next.js: use NEXT_PUBLIC_SITECORE_EDGE_PLATFORM_HOSTNAME for client; SITECORE_EDGE_PLATFORM_HOSTNAME for server-only.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Next.js: use NEXT_PUBLIC_SITECORE_EDGE_PLATFORM_HOSTNAME for client; SITECORE_EDGE_PLATFORM_HOSTNAME for server-only.

NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID=

# Optional: custom Sitecore Edge Platform hostname (hostname or full URL).
# Next.js: use NEXT_PUBLIC_SITECORE_EDGE_PLATFORM_HOSTNAME for client; SITECORE_EDGE_PLATFORM_HOSTNAME for server-only.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Next.js: use NEXT_PUBLIC_SITECORE_EDGE_PLATFORM_HOSTNAME for client; SITECORE_EDGE_PLATFORM_HOSTNAME for server-only.

Comment on lines 8 to 13
const DEFAULT_EDGE_HOSTNAMES = [
'edge-platform.sitecorecloud.io',
'edge.sitecorecloud.io',
'edge-staging.sitecore-staging.cloud',
'edge-platform-staging.sitecore-staging.cloud',
] as const;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refer to my previous comment - the issue has not been resolved yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants