A 404 Not Found error might occur when accessing a custom API route in a Next.js application using Pages editor and preview mode.
This issue arises due to a hostname mismatch, where the request is sent to the XM Cloud CM (Content Management) hostname instead of the editing host. The relative path specified relies on the current hostname, leading to the error.
To address the issue proceed as follows:
await fetch(publicUrl + "/api/customApiEndpoint");