nomadro/next.config.ts
Eric abdcafb1eb Ship Work access gate, pads/boards upgrades, and locale hydration fix on .com.
Gate /social/work behind join/login/profile; harden Work UX and LanguageSwitcher SSR; deploy portal, admin, and work API.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-08 00:14:39 +08:00

169 lines
5.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import path from "node:path";
import type { NextConfig } from "next";
const API_URL = (process.env.API_URL || "http://127.0.0.1:8080").replace(
/\/$/,
"",
);
/** Social IM is isolated (nomadro-social / portal nginx /rt). Never assume api.* hosts it. */
const SOCIAL_API_URL = (
process.env.SOCIAL_API_URL ||
(/\bapi\.nomadro\.(com|cn)\b/i.test(API_URL)
? API_URL.replace(/\bapi\.(nomadro\.(?:com|cn))\b/i, "$1")
: API_URL)
).replace(/\/$/, "");
/**
* Micro-frontend upstreams (Planka / Etherpad).
* Local without Docker: set WORK_*_ORIGIN in `.env.local` (e.g. US host :1337/:9001).
*/
const WORK_PLANKA_ORIGIN = (
process.env.WORK_PLANKA_ORIGIN || "http://127.0.0.1:1337"
).replace(/\/$/, "");
const WORK_ETHERPAD_ORIGIN = (
process.env.WORK_ETHERPAD_ORIGIN || "http://127.0.0.1:9001"
).replace(/\/$/, "");
if (process.env.NODE_ENV !== "production") {
console.info(
`[work] planka-api→${WORK_PLANKA_ORIGIN} etherpad→${WORK_ETHERPAD_ORIGIN}`,
);
}
/** 门户前端均在 src/;禁止再指向已删除的垂直仓 */
const aliases = {
"@ebook": path.resolve(__dirname, "src/modules/ebook"),
"@community": path.resolve(__dirname, "src/modules/community"),
"@social": path.resolve(__dirname, "src/modules/social"),
"@navmini": path.resolve(__dirname, "src/modules/nav"),
"@vip": path.resolve(__dirname, "src/modules/vip"),
"@work": path.resolve(__dirname, "src/modules/work"),
"@nomadro/pay": path.resolve(__dirname, "packages/pay/src/index.ts"),
"@nomadro/pb": path.resolve(__dirname, "packages/pb/src/index.ts"),
"@nomadro/sdk": path.resolve(__dirname, "packages/sdk/src/index.ts"),
};
const nextConfig: NextConfig = {
poweredByHeader: false,
compress: true,
experimental: {
externalDir: true,
optimizePackageImports: [
"antd",
"@ant-design/icons",
"lucide-react",
"framer-motion",
"three",
],
},
images: {
formats: ["image/avif", "image/webp"],
remotePatterns: [
{ protocol: "https", hostname: "**.nomadro.cn" },
{ protocol: "https", hostname: "**.nomadro.com" },
{ protocol: "https", hostname: "s3.nomadro.com" },
{ protocol: "https", hostname: "api.dicebear.com" },
],
},
transpilePackages: ["@nomadro/pay", "@nomadro/pb", "@nomadro/sdk"],
turbopack: {
resolveAlias: {
"@ebook": "./src/modules/ebook",
"@community": "./src/modules/community",
"@social": "./src/modules/social",
"@navmini": "./src/modules/nav",
"@vip": "./src/modules/vip",
"@work": "./src/modules/work",
"@nomadro/pay": "./packages/pay/src/index.ts",
"@nomadro/pb": "./packages/pb/src/index.ts",
"@nomadro/sdk": "./packages/sdk/src/index.ts",
},
},
webpack: (config, { dev }) => {
config.resolve.alias = {
...config.resolve.alias,
...aliases,
};
// PB 库文件一直在写(*.db-wal/shm);不忽略会触发 Fast Refresh 全页闪烁花屏
if (dev) {
config.watchOptions = {
...config.watchOptions,
ignored: [
"**/node_modules/**",
"**/.git/**",
"**/pb/pb_data/**",
"**/pb_data/**",
"**/*.db",
"**/*.db-*",
"**/__pycache__/**",
"**/.next/**",
],
};
}
return config;
},
async rewrites() {
return [
{
source: "/vip/ebook/read",
destination: "/vip/ebook-read",
},
{
source: "/vip/ebook/read/:path*",
destination: "/vip/ebook-read",
},
{
source: "/vip/ebook/cloudphone",
destination: "/vip/ebook-cloudphone",
},
{
source: "/api/v1/:path*",
destination: `${API_URL}/api/v1/:path*`,
},
{
source: "/api/social/:path*",
destination: `${SOCIAL_API_URL}/api/social/:path*`,
},
// Local Centrifugo (scripts/dev-centrifugo.ps1). Prod uses nginx /rt/ on the portal host.
{
source: "/rt",
destination: `${process.env.CENTRIFUGO_HTTP_ORIGIN || "http://127.0.0.1:8008"}/`,
},
{
source: "/rt/:path*",
destination: `${process.env.CENTRIFUGO_HTTP_ORIGIN || "http://127.0.0.1:8008"}/:path*`,
},
// Planka server API/socket only (UI is native Next from forked client)
{
source: "/work-api",
destination: `${WORK_PLANKA_ORIGIN}/`,
},
{
source: "/work-api/:path*",
destination: `${WORK_PLANKA_ORIGIN}/:path*`,
},
// Etherpad still path-proxied until pad UI is ported
{
source: "/work-mf/etherpad",
destination: `${WORK_ETHERPAD_ORIGIN}/`,
},
{
source: "/work-mf/etherpad/:path*",
destination: `${WORK_ETHERPAD_ORIGIN}/:path*`,
},
];
},
async headers() {
return [
{
source: "/:path*",
headers: [
{ key: "X-Content-Type-Options", value: "nosniff" },
{ key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
],
},
];
},
};
export default nextConfig;