1

For my new Sitecore 10.2 XM instance I have set up Headless Services 19.0 on the CM and CD instances as described on the docs site.

When I test the endpoint on the CM server https://<CM Url>/sitecore/api/layout/render/jss?item=/&sc_apikey=<Guid of key> the Layout Services correctly returns the json for that Item.

However, when I test the endpoint for the CD Server https://<CD Url>/sitecore/api/layout/render/jss?item=/&sc_apikey=<Guid of key> a 404 response is returned without json.

I've gone through the usual steps;

  1. Ensured that the key is correct and published
  2. Disabled custom 404 handlers
  3. Ensured the dlls, configs, views, and sitecore folder is copied from the package
  4. Ensured the package is the correct package i.e. for XM
  5. Added the sitecorejss_media.ashx handler in the correct place

However the CM still returns json and the CD server returns a 404 with nothing in the logs.

1
  • Hey mate, any luck on that issue. I am having same issue in my sitecore environment?
    – Arun Kumar
    Jun 2, 2022 at 12:16

2 Answers 2

1
+50

This is likely caused by one of two issues:

  1. The API key is incorrectly configured (less likely given the symptoms)
  2. The Headless Services package is missing required configuration on the CD role. (most likely)

To ensure the API key is configured properly, the CORS Origins and Allowed Controllers fields should be set to: *

API Key Configuration

I'm making a big assumption that you are attempting this in an On-Prem or Azure PaaS environment and are not using containers.

To ensure that Headless Services are installed properly on your CD, you should be using the Sitecore Headless Services CD WDP for Sitecore XM from the Sitecore downloads page

Sitecore Headless Services CD WDP for Sitecore XM

https://dev.sitecore.net/Downloads/Sitecore%20Headless%20Rendering/19x/Sitecore%20Headless%20Rendering%201900

If you haven't worked with Sitecore Web Deploy Packages (.scwdp) before, they are compressed files that you can unpack and manually copy all of the assets from this package to the root of your CD website.

Headless Services SCWDP Folder Structure

If neither of these two options work for you, take a look at your ShowConfig for the ContentDelivery role.

https://<CM Url>/sitecore/admin/showconfig.aspx?layer=Sitecore|Modules|Custom|Environment&role=ContentDelivery

Make sure that these pipelines are present:

    <pipelines>
      <initialize>
        <processor type="Sitecore.LayoutService.Mvc.Pipelines.Initialize.RegisterRoutes, Sitecore.LayoutService.Mvc"
                   patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeRoutes, Sitecore.Mvc']"
                   resolve="true" />
      </initialize>
      <httpRequestBegin>
        <processor type="Sitecore.LayoutService.Mvc.Pipelines.HttpRequestBegin.SkipContextItemResolutionWhenLayoutServiceRequest, Sitecore.LayoutService.Mvc"
                   resolve="true"
                   patch:before="processor[contains(@type, 'ItemResolver')]"/>
      </httpRequestBegin>
      <mvc.requestBegin>
        <processor type="Sitecore.LayoutService.Mvc.Pipelines.RequestBegin.ContextItemResolver, Sitecore.LayoutService.Mvc"
                   patch:after="processor[@type='Sitecore.Mvc.Pipelines.Request.RequestBegin.EnsureLoggedInForPreview, Sitecore.Mvc']"
                   resolve="true" />
      </mvc.requestBegin>
    </pipelines>

These are configured within the file: .\App_Config\Sitecore\LayoutService\Sitecore.LayoutService.Mvc.config

You can also quickly confirm whether Headless Server is installed correctly in ContentDelivery by checking the GraphQL playground using this url:

https://<CD Url>/sitecore/api/graph/edge/ui

1
  • The problem was actually with my web.config blocking /sitecore in the location. All sorted now. but I would mark this as a answer because it gives a good information about what could go wrong.
    – Arun Kumar
    Jun 4, 2022 at 0:16
0

If you get a 404 there might be an issue with the allowedControllers. Since the layout service is also just a controller (Sitecore.LayoutService.Mvc.Controllers.LayoutServiceController in Sitecore.LayoutService.Mvc) it needs to be allowed on both CM and CD. Did you change anything in that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.