feat: separate frontend and backend services

This commit is contained in:
luckyyzh
2026-08-10 09:45:22 +08:00
parent cb9ec7a869
commit 7a9859e60d
132 changed files with 8393 additions and 6388 deletions
+20 -8
View File
@@ -5,7 +5,7 @@ import { join } from "path";
const { version } = JSON.parse(readFileSync(join(__dirname, "package.json"), "utf8")) as { version: string };
let piVersion = "unknown";
try {
const piPkgPath = join(__dirname, "node_modules/@earendil-works/pi-coding-agent/package.json");
const piPkgPath = join(__dirname, "..", "server", "node_modules", "@earendil-works", "pi-coding-agent", "package.json");
piVersion = (JSON.parse(readFileSync(piPkgPath, "utf8")) as { version: string }).version;
} catch { /* package not found, use default */ }
@@ -14,16 +14,28 @@ const allowedDevOrigins = [
...(process.env.PI_WEB_ALLOWED_HOSTS?.split(",") ?? []),
].map((origin) => origin.trim()).filter(Boolean);
// All /api routes are served by the standalone backend (pi-agent-server) so
// agent sessions and server state survive frontend recompiles and restarts.
const serverOrigin = `http://127.0.0.1:${process.env.PI_SERVER_PORT ?? "30142"}`;
const nextConfig: NextConfig = {
devIndicators: false,
serverExternalPackages: [
"undici",
"@earendil-works/pi-coding-agent",
"@earendil-works/pi-agent-core",
"@earendil-works/pi-ai",
"@earendil-works/pi-tui",
],
allowedDevOrigins,
async rewrites() {
// beforeFiles is required: default (afterFiles) rewrites lose to the
// existing app/api route handlers in dev, so the migrated routes
// would keep hitting the local copies instead of the backend.
return {
beforeFiles: [
{
source: "/api/:path*",
destination: `${serverOrigin}/api/:path*`,
},
],
afterFiles: [],
fallback: [],
};
},
async headers() {
return [
{