From f902c9fe2f7839788a3ba31fd1615f160b86a385 Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Fri, 17 Apr 2026 08:55:30 +0200 Subject: [PATCH] fix(papermark): patch middleware to allow IP-based access in self-hosted mode isCustomDomain() in middleware.ts treats any non-localhost/papermark.*/vercel host as a custom domain in production, causing DomainMiddleware to redirect / to https://www.papermark.com when no Redis entry exists. Fix: patch middleware.ts before build to exclude IP addresses from custom domain detection. --- install/papermark-install.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/install/papermark-install.sh b/install/papermark-install.sh index b50a0795..2c683d4b 100644 --- a/install/papermark-install.sh +++ b/install/papermark-install.sh @@ -43,6 +43,17 @@ EOF $STD npm install $STD npx prisma generate $STD npx prisma migrate deploy +# Patch middleware to treat IP addresses as app host (not custom domains) +# Without this, accessing via IP redirects to https://www.papermark.com +node -e " +const fs = require('fs'); +let c = fs.readFileSync('middleware.ts', 'utf8'); +c = c.replace( + 'host?.endsWith(\".vercel.app\")', + 'host?.endsWith(\".vercel.app\") || /^[\\\\d.:]+\$/.test(host || \"\")' +); +fs.writeFileSync('middleware.ts', c); +" NODE_OPTIONS="--max-old-space-size=3584" $STD npm run build msg_ok "Set up Papermark"