1

We are working on 10.2 Sitecore JSS (NextJS) using SXA. We have enabled Sitemap.xml in Sitecore using OOTB SXA settings. We can see sitemap item at this path /sitecore/content/TenantName/Home/Settings/Sitemap The sitemap.xml URL is working fine for the Sitecore domain (CM server), we can see all the desired URLs.

Our NextJS application is hosted on Vercel, but when we check the sitemap.xml URL in the Vercel domain, it gives a 404 error.

Does any specific thing need to be enabled to make sitemap.xml work for NextJS application hosted on Vercel?

Update:

  • We are fetching layout data with the JSS REST Layout Service.
  • Sitemap.xml is not working on localhost:3000 as well.
2

2 Answers 2

3

If that works on local and not on Vercel, then I suspect its related to configuration (as you said). Here are details of how its implementation uses configuration and you can check those.

With SXA setup, you get a sitemap-fetcher plugin. It resides at path - src\rendering\src\lib\sitemap-fetcher\plugins\graphql-sitemap-service.ts

If you check its constructor -

constructor() {
this._graphqlSitemapService = new GraphQLSitemapService({
  endpoint: config.graphQLEndpoint,
  apiKey: config.sitecoreApiKey,
  siteName: config.jssAppName,
});

Assuming you are using GraphQl endpoint, you will need to share AppName if you have multisite setup in environment variables.

Second thing to look at is it's implementation,

async exec(context?: GetStaticPathsContext): Promise<StaticPath[]> {
    if (process.env.JSS_MODE === constants.JSS_MODE.DISCONNECTED) {
      return [];
    }
    return process.env.EXPORT_MODE
      ? this._graphqlSitemapService.fetchExportSitemap(config.defaultLanguage)
      : this._graphqlSitemapService.fetchSSGSitemap(context?.locales || []);
  }

If you have multilingual setup, you can check your default language (in config.json).

If this is all well then you can check if GraphQl query returns Sitemap.

EDIT 1 - If you are using Experience Edge, you will need to store Sitemap in Media Item (This is recommended for Cloud version but no harm in trying).

enter image description here

https://doc.sitecore.com/xmc/en/developers/xm-cloud/configure-a-sitemap.html

And make sure that you have media folder selected in Site Item's Sitemap media items field -

enter image description here

2
  • Thanks for your response. It is not working on our local as well. It is working on <SitecoreCMDoamin>/sitemap.xml but not working on localhost:3000/sitemap.xml. We are using rest API layout service. Commented Jul 28, 2023 at 7:25
  • 1
    I have not used REST Api but I just see fetchers for GraphQl and Disconnected mode. So I am not very sure that it will work OOTB. Btw are you using Experience Edge ? If yes, I am adding some information in answer, do check if that helps. Commented Jul 28, 2023 at 14:41
3

Navigate to /sitecore/content/Tenant/Site/Settings --> In this set the sitemap mode field to store in the file, similarly, navigate to /sitecore/content/Tenant/Site/Settings/Sitemap and set the cache type field to store in the file.

After setting the field values publish your site and this should work.

Note: After publishing the site the sitemap.xml gets map to sitemap media item in your site (click on site to check) if it is not mapped you won't be able to see the sitemap in localhost/Vercel Settings/Sitemap

Settings

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.