Self-host on own host: middleware rewrites every page to /view/domains
On any self-host hostname other than localhost / papermark.io / papermark.com / *.vercel.app, the edge middleware rewrites every path to /view/domains/<host><path> — the custom-domain dataroom handler — so the app shows a spinner instead of the real page. /login is broken, and there's no built-in way to disable this.
$ curl -i https://papermark.example.com/login
HTTP/2 200
x-middleware-rewrite: /view/domains/papermark.example.com/login
… { "page":"/view/domains/[domain]/[slug]", "isFallback":true }The gated branch in middleware.js is a hardcoded list:
if (r?.includes("localhost") ||
r?.includes("papermark.io") ||
r?.includes("papermark.com") ||
r?.endsWith(".vercel.app")) { /* normal routing */ }
else { iO(e); /* rewrite to /view/domains/<host><path> */ }r is request.headers.get("host"). NEXT_PUBLIC_ENABLE_CUSTOM_DOMAINS=false doesn't help — it's a NEXT_PUBLIC_* var inlined at build time, and the published image wasn't built with it set.
The configured primary domain (PAPERMARK_DOMAIN / NEXT_PUBLIC_APP_BASE_HOST) should be treated as a known host (or honoring NEXT_PUBLIC_ENABLE_CUSTOM_DOMAINS=false should disable the rewrite). Maybe related to #1353, #1956.
Workaround: add the self-host host to the predicate list.
FROM ghcr.io/avnox-com/papermark:latest
RUN sed -i 's|r?.endsWith(".vercel.app"))|r?.endsWith(".vercel.app")\|\|r?.includes("papermark.example.com"))|' /app/.next/server/middleware.jsghcr.io/avnox-com/papermark:latest, Next.js 14.2.35.
Source: papermark/papermark