We previously showed you how to connect your local Next.js project to XM Cloud. So is it easy to do this if you are running in a local container? In this article, we will check this.
![](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F4SgSN5iBZDWwTs87nf5JfC%2Fccdbfd7cb1ed848019547354c0562fcb%2Felena-mozhvilo-CwIOnANQW-A-unsplash.jpg&w=3840&q=75)
Prerequisite
We will check the configuration of the CM server of XM Cloud that is running locally. First, in the default configuration, the hostname is as follows
- https://xmcloudcm.localhost
Then go into the CM server and get the API key. You will use the ID of the item in /sitecore/system/Settings/Services/API Keys/xmcloudpreview. Set these two values in src\sxastarter\.env.
![xmclocal01.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F4N8oybgzjCw0MVCGUMlJ2t%2Fbd8980d677f34c5b5ab2b583e9d6d0b5%2Fxmclocal01.png&w=3840&q=75)
We are now ready to go. Try connecting with the following command.
jss start:connected
After startup, the following error message appears
▲ Next.js 13.5.3
- Local: http://localhost:3000
- Environments: .env
✓ Ready in 3.1s
✓ Compiled /src/middleware in 279ms (202 modules)
✓ Compiled /[[...path]] in 463ms (587 modules)
✓ Compiled /_error in 272ms (587 modules)
⨯ FetchError: request to https://xmcloudcm.localhost/sitecore/api/graph/edge failed, reason: unable to verify the first certificate
at ClientRequest.<anonymous> (C:\projects\xmc-demo-jp\src\sxastarter\node_modules\@sitecore-jss\sitecore-jss\node_modules\node-fetch\lib\index.js:1501:11)
at ClientRequest.emit (node:events:517:28)
at TLSSocket.socketErrorListener (node:_http_client:501:9)
at TLSSocket.emit (node:events:517:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
type: 'system',
errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
page: '/_site_sitecoredemo-jp'
}
This is an error when Node.js tries to access a Sitecore instance that is up and running with a self-certificate.
![xmclocal02.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F7rOpiFOoe8EFhPeLb3LuA0%2Fb7456d4d62251ed4fbffcc8ca7aca6d4%2Fxmclocal02.png&w=3840&q=75)
As a workaround, add the following line to the .env file
NODE_TLS_REJECT_UNAUTHORIZED=0
Now you can access the local CMS and check the page display.
![xmclocal02.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2FpTUBJqAbHaOCA1vBST6kf%2F9e3588de2a316c5dd8340e734aecb081%2Fxmclocal02.png&w=3840&q=75)
Summary
This setting is only available locally using a self-certificate, so it is not necessary to set it for XM Cloud, which is actually running on SaaS. Use this setting as needed.