nomadro/next.config.ts
eric d93a355fd5 Migrate navmini/ebook/nomadweb into apps/ as same-origin portal subpaths.
Shield external portal jumps (keep EXTERNAL_* for later), serve /nav from static build, and proxy /book + /community to vertical Next apps with Caddy notes.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-28 03:30:34 -05:00

60 lines
1.6 KiB
TypeScript

import fs from "node:fs";
import path from "node:path";
import type { NextConfig } from "next";
/**
* Portal reverse-proxies vertical apps so /nav /book /community stay same-origin.
* Override upstreams via env when deploying or local multi-process dev.
*/
const NAV_UPSTREAM = (process.env.NAV_UPSTREAM || "http://127.0.0.1:5173").replace(
/\/$/,
"",
);
const BOOK_UPSTREAM = (
process.env.BOOK_UPSTREAM || "http://127.0.0.1:3001"
).replace(/\/$/, "");
const COMMUNITY_UPSTREAM = (
process.env.COMMUNITY_UPSTREAM || "http://127.0.0.1:3002"
).replace(/\/$/, "");
const hasStaticNav = fs.existsSync(
path.join(process.cwd(), "public", "nav", "index.html"),
);
const nextConfig: NextConfig = {
async rewrites() {
const beforeFiles = hasStaticNav
? [
{ source: "/nav", destination: "/nav/index.html" },
{ source: "/nav/", destination: "/nav/index.html" },
]
: [];
const fallback = [
...(hasStaticNav
? []
: [
{ source: "/nav", destination: `${NAV_UPSTREAM}/nav/` },
{
source: "/nav/:path*",
destination: `${NAV_UPSTREAM}/nav/:path*`,
},
]),
{ source: "/book", destination: `${BOOK_UPSTREAM}/book` },
{ source: "/book/:path*", destination: `${BOOK_UPSTREAM}/book/:path*` },
{
source: "/community",
destination: `${COMMUNITY_UPSTREAM}/community`,
},
{
source: "/community/:path*",
destination: `${COMMUNITY_UPSTREAM}/community/:path*`,
},
];
return { beforeFiles, fallback };
},
};
export default nextConfig;