somratpro Claude Opus 4.7 commited on
Commit
0234a7a
Β·
1 Parent(s): c4c4e4c

fix: redirect bare paths to /app/ and disable image optimization

Browse files

Post-login 404: Postiz navigates to /launches (no basePath prefix) after
auth; health-server now redirects any unrecognized path to /app<path>
instead of 404-ing.

_next/image 400s: disable Next.js image optimization (unoptimized:true in
next.config.js) so <Image> renders plain <img src="/app/auth/avatars/...">
tags that route through nginx correctly, bypassing the optimizer's internal
fetch which failed because static files live at the basePath-prefixed path.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

Files changed (2) hide show
  1. Dockerfile +10 -0
  2. health-server.js +6 -3
Dockerfile CHANGED
@@ -63,6 +63,16 @@ RUN sed -i "s|const nextConfig = {|const nextConfig = {\n basePath: '/app',\n
63
  && grep -q "swcMinify: false" apps/frontend/next.config.js \
64
  && grep -q "cpus: 1" apps/frontend/next.config.js \
65
  || (echo "PATCH FAILED β€” next.config.js shape changed upstream"; exit 1)
 
 
 
 
 
 
 
 
 
 
66
 
67
  ENV SENTRY_DSN="" \
68
  SENTRY_AUTH_TOKEN="" \
 
63
  && grep -q "swcMinify: false" apps/frontend/next.config.js \
64
  && grep -q "cpus: 1" apps/frontend/next.config.js \
65
  || (echo "PATCH FAILED β€” next.config.js shape changed upstream"; exit 1)
66
+ # Patch: disable Next.js image optimisation.
67
+ # With basePath="/app", the _next/image optimizer fetches static files from
68
+ # Next.js's internal URL without the basePath prefix, causing 400 errors.
69
+ # unoptimized:true makes <Image> render as plain <img> tags; the browser
70
+ # fetches /app/auth/avatars/… which routes correctly through nginx.
71
+ # If Postiz already has an images:{} block, inject unoptimized inside it;
72
+ # otherwise add a new images block at the top of nextConfig.
73
+ RUN grep -q 'images:' apps/frontend/next.config.js \
74
+ && sed -i 's|images: {|images: {\n unoptimized: true,|' apps/frontend/next.config.js \
75
+ || sed -i "s|const nextConfig = {|const nextConfig = {\n images: { unoptimized: true },|" apps/frontend/next.config.js
76
 
77
  ENV SENTRY_DSN="" \
78
  SENTRY_AUTH_TOKEN="" \
health-server.js CHANGED
@@ -858,9 +858,12 @@ const server = http.createServer((req, res) => {
858
  return;
859
  }
860
 
861
- // ── Anything else β†’ 404 ──────────────────────────────────────────────────
862
- res.writeHead(404, { "Content-Type": "text/plain" });
863
- res.end("Not found. Try / for the dashboard or /app for Postiz.");
 
 
 
864
  });
865
 
866
  server.on("upgrade", (req, socket, head) => {
 
858
  return;
859
  }
860
 
861
+ // ── Anything else β†’ redirect to /app<path> ──────────────────────────────
862
+ // After login, Postiz's client-side router may navigate to a path without
863
+ // the /app basePath prefix (e.g. /launches, /analytics, /api/...).
864
+ // Redirect those here rather than 404-ing so the browser lands correctly.
865
+ res.writeHead(302, { Location: "/app" + pathname + (parsedUrl.search || "") });
866
+ res.end();
867
  });
868
 
869
  server.on("upgrade", (req, socket, head) => {