The site router answers 500 on attachment and scaled-image URLs
-
What you'll see
You protect a site with a router, as described in Use the site router for your own sign-in and API tokens or in the two-layer model, and link files and thumbnails with
linkFileandlinkImage. Pages and API calls work. Every embedded file and every scaled image returns 500. -
What's actually happening
The site console shows
The router #/Services/Router.js failed … Specified path is emptyfor these URLs. The error happens before your router function runs. Measured 2026-11-28 with a router reduced toreturn route.next()and no imports: the attachment URL and alinkImageURL (…/160x200x1/brochure.webp) both returned 500. The same URLs return 200 on a publication without a router. The KB article Images that should be scaled cannot live under the # folder describes these URLs as passing through the router. With this bug they do not. -
What to do
Workaround until the platform is fixed: give the files an API endpoint that runs the same access rule as the router and returns the bytes. This version is in production use (measured 2026-11-28):
// #/API/Thumbnail.js - GET ?path=<file path> import { requireUser, canSeePath } from "#/Libs/Access.js"; export default () => { const user = requireUser(); const path = ("" + (query.path || "")).trim(); if (!path || path.indexOf("..") >= 0 || path.replace(/^\/+/, "").startsWith("#")) throw { error: "Invalid file." }; const f = docly.getFile(path); if (!f || !f.File) throw { error: "File not found." }; // check access on the folder the document actually lives in, not on what the caller sent if (!canSeePath(user, f.folderpath + "/" + f.filename)) { docly.denyAccess(); throw { error: "No access." }; } const data = docly.getEmbeddedFile(f.filepath, f.File); const image = docly.scaleImage(data, 160, 200, { mode: "ScaleToFit", format: "webp" }); return docly.downloadBytes(image, "preview.webp", true); };scaleImagealso renders the first page of a PDF.downloadBytescurrently drops headers set withsetHeader, so put a version in the URL (?v=<LastModified>) instead of relying on browser caching (see downloadBytes ignores headers set with setHeader). Remove the workaround when this entry is marked Resolved.
Last reviewed 28 Nov 2026