mirror of
https://github.com/luckyyzh/pi-agent-integrated.git
synced 2026-10-03 02:59:35 +00:00
feat: separate frontend and backend services
This commit is contained in:
+20
-8
@@ -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 [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user