Links in markup an API returns do not get the mount path
-
What you'll see
A list or fragment you load from
/API/...and insert withinnerHTMLworks on the site's own domain, but its links and images give 404 when the site is published under a path such as/MySite/. -
What's actually happening
When Docly renders a page (
.hash, display templates), it rewriteshrefandsrcvalues that start with/so that they include the path the folder is published under. An API script's response is not rewritten: a string of markup in the JSON reaches the browser exactly as the script built it. Built from the same helpers as the page, the markup then points at the root of the domain instead of the site.On a site published at the root of its own domain the two are the same, so the fault only shows on a staging address or any other path.
-
What to do
Prefix the paths in the API script with
request.sitepathbefore returning the markup:function mounted(html) { const root = String(request.sitepath || "/").replace(/\/?$/, "/"); return root == "/" ? html : html.replace(/(\s(?:href|src))="\/(?!\/)/g, '$1="' + root); } return { html: mounted(listHtml(items)) };- Do it once, where the response is built, not in every helper: the helpers stay usable from pages, where Docly already adds the path.
- The same applies to
docly.redirectin an API script; see Convert an existing website to Docly. - Test the site under a path before it moves to its own domain.
Last reviewed 26 Oct 2026