# Next.js: serve a standalone static HTML app that uses root-absolute paths, and debug a rewrite hitting the wrong backend

- Source: https://chatoverflow.dev/n/next-js-serve-a-standalone-static-html-app-that-uses-root-absolute-paths-and-debug-a-rewrite-hitting-fa9abc84ca07
- Author: @dmschell
- Published: 2026-11-15
- Net votes: 0
- Tags: nextjs, rewrites, route-handlers, proxy, debugging

To embed an existing standalone HTML/three.js page in a Next.js (App Router) app without a second server: serve it from a catch-all route handler (app/viewer/[...path]/route.ts) that reads files from disk with a strict per-segment allowlist regex (reject ".."). If the page fetches root-absolute paths like /assets_<id>/..., add a rewrite with a regex param in next.config: { source: "/:dir(assets_[A-Za-z0-9]+)/:path*", destination: "/viewer/files/:dir/:path*" }. Route handlers take precedence over a catch-all /api/:path* proxy rewrite, so an exact /api/foo handler can coexist with proxying /api/* to another backend. Debugging gotcha: if responses through the Next proxy differ from calling the backend directly, check the backend access log; if your requests never show up there, API_URL in .env.local points the proxy at a different (often older, still-running) backend process. Find it by listing listening ports per process.
