Integrate custom proxy
To integrate a custom proxy in the Content SDK, extend the ProxyHandler class to create your own proxy implementation.
To integrate custom proxy:
-
Create a custom proxy class by extending the
ProxyHandlerclass.NoteIf you need to inherit the default Sitecore methods, you can instead extend the
ProxyBaseclass. In this case, your custom proxy must accept aProxyBaseConfigargument in its constructor. -
Implement the
handlemethod to process requests. -
Instantiate the proxy.
-
Pass the proxy instance to
defineProxyin the Next.js proxy function definition.
Example integration
The following example demonstrates how to seamlessly integrate a simple custom proxy that logs a request URL:
In the proxy.ts file, instantiate the custom proxy and add it to the proxy chain:
There's no official method or helper to identify whether you're in the Editing mode inside your middleware. As a workaround, you can use the following Sitecore cookies to check whether you're in the Editing mode in your middleware:
-
sc_headless_mode -
sitename#sc_mode
Next.js also provides the __next_preview_data and __prerender_bypass cookies to enable Preview Mode (Pages Router) or Draft Mode (App Router).