Headless site with SXA is unable to connect to Sitecore server with ContentDelivery role


Description

When working on the SXA deployment on JSS and altering the Layout Service configuration to sxa-jss, the following error might occur during page rendering:

Server Error in '/' Application.
Could not find configuration node: databases/database[@id='master']
Description: An unhandled exception occurred.

Exception Details: System.InvalidOperationException: Could not find configuration node: databases/database[@id='master']

This issue occurs when the headless application fails to establish a connection with the Sitecore server, which is operating in the ContentDelivery role, due to the site’s database being set to Web. Therefore, the Master database becomes inaccessible, causing the Next.js application to fail in its attempt to connect to Sitecore.

Solution

To resolve the issue, upgrade your solution to Sitecore XP 10.4.0 or later.

Alternatively, to mitigate the issue, patch the setting with the following value for <databaseName> tag on CD server by creating a configuration patch file.

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
    <sitecore>
        <layoutService>
            <configurations>
                <config name="sxa-jss">
                    <requestContext type="Sitecore.LayoutService.Configuration.DefaultRequestContext, Sitecore.LayoutService">
                        <databaseName>web</databaseName>
                    </requestContext>
                </config>
            </configurations>
        </layoutService>
    </sitecore>
</configuration>