feat: single-port architecture and browser warning fixes (#390)
This commit is contained in:
+1
-2
@@ -28,7 +28,7 @@ export async function runDev({ repoRoot, backendPort, webPort }: DevOptions): Pr
|
||||
KANDEV_MOCK_AGENT: process.env.KANDEV_MOCK_AGENT || "true",
|
||||
};
|
||||
const backendEnv = buildBackendEnv({ ports, extra });
|
||||
const webEnv = buildWebEnv({ ports, includeMcp: true, debug: true });
|
||||
const webEnv = buildWebEnv({ ports, debug: true });
|
||||
const logLevel =
|
||||
process.env.KANDEV_LOGGING_LEVEL?.trim() || process.env.KANDEV_LOG_LEVEL?.trim() || "info";
|
||||
|
||||
@@ -36,7 +36,6 @@ export async function runDev({ repoRoot, backendPort, webPort }: DevOptions): Pr
|
||||
header: "dev mode: using local repo",
|
||||
ports,
|
||||
dbPath,
|
||||
includeMcp: true,
|
||||
logLevel,
|
||||
});
|
||||
|
||||
|
||||
+3
-3
@@ -174,6 +174,7 @@ async function prepareReleaseBundle({
|
||||
const backendEnv = {
|
||||
...process.env,
|
||||
KANDEV_SERVER_PORT: String(actualBackendPort),
|
||||
KANDEV_WEB_INTERNAL_URL: `http://localhost:${actualWebPort}`,
|
||||
KANDEV_AGENT_STANDALONE_PORT: String(agentctlPort),
|
||||
KANDEV_DATABASE_PATH: dbPath,
|
||||
KANDEV_LOG_LEVEL: logLevel,
|
||||
@@ -182,7 +183,6 @@ async function prepareReleaseBundle({
|
||||
const webEnv: NodeJS.ProcessEnv = {
|
||||
...process.env,
|
||||
KANDEV_API_BASE_URL: backendUrl,
|
||||
NEXT_PUBLIC_KANDEV_API_BASE_URL: backendUrl,
|
||||
PORT: String(actualWebPort),
|
||||
};
|
||||
(webEnv as Record<string, string>).NODE_ENV = "production";
|
||||
@@ -264,6 +264,6 @@ export async function runRelease({ version, backendPort, webPort }: RunOptions):
|
||||
quiet: true,
|
||||
});
|
||||
await waitForUrlReady(webUrl, webProc, healthTimeoutMs);
|
||||
console.log(`[kandev] web ready at ${webUrl}`);
|
||||
openBrowser(webUrl);
|
||||
console.log("[kandev] ready at " + prepared.backendUrl);
|
||||
openBrowser(prepared.backendUrl);
|
||||
}
|
||||
|
||||
+9
-22
@@ -67,6 +67,7 @@ export function buildBackendEnv(options: BackendEnvOptions): NodeJS.ProcessEnv {
|
||||
return {
|
||||
...process.env,
|
||||
KANDEV_SERVER_PORT: String(ports.backendPort),
|
||||
KANDEV_WEB_INTERNAL_URL: `http://localhost:${ports.webPort}`,
|
||||
KANDEV_AGENT_STANDALONE_PORT: String(ports.agentctlPort),
|
||||
KANDEV_AGENT_MCP_SERVER_PORT: String(ports.mcpPort),
|
||||
...(logLevel ? { KANDEV_LOG_LEVEL: logLevel } : {}),
|
||||
@@ -76,8 +77,6 @@ export function buildBackendEnv(options: BackendEnvOptions): NodeJS.ProcessEnv {
|
||||
|
||||
export type WebEnvOptions = {
|
||||
ports: PortConfig;
|
||||
/** Include MCP URL environment variables (used in dev/start modes) */
|
||||
includeMcp?: boolean;
|
||||
/** Set NODE_ENV to production */
|
||||
production?: boolean;
|
||||
/** Enable debug mode (NEXT_PUBLIC_KANDEV_DEBUG) */
|
||||
@@ -91,25 +90,18 @@ export type WebEnvOptions = {
|
||||
* @returns Environment object for the web process
|
||||
*/
|
||||
export function buildWebEnv(options: WebEnvOptions): NodeJS.ProcessEnv {
|
||||
const { ports, includeMcp = false, production = false, debug = false } = options;
|
||||
const { ports, production = false, debug = false } = options;
|
||||
|
||||
// Server-side env vars use localhost (SSR runs on same machine as backend)
|
||||
// Client-side uses NEXT_PUBLIC_*_PORT to build URLs dynamically from window.location.hostname
|
||||
// This allows accessing the app from any device (iPhone, Tailscale, etc.)
|
||||
const env: NodeJS.ProcessEnv = {
|
||||
...process.env,
|
||||
// Server-side: full localhost URL for SSR
|
||||
// Server-side: full localhost URL for SSR fetches (Next.js SSR → Go backend)
|
||||
KANDEV_API_BASE_URL: ports.backendUrl,
|
||||
// Client-side: only pass ports, client builds URL from current hostname
|
||||
// Client-side: port injection for dev mode (browser on :3000, API on :8080).
|
||||
// In production, the backend reverse-proxies Next.js so the client uses same-origin.
|
||||
NEXT_PUBLIC_KANDEV_API_PORT: String(ports.backendPort),
|
||||
PORT: String(ports.webPort),
|
||||
};
|
||||
|
||||
if (includeMcp) {
|
||||
env.KANDEV_MCP_SERVER_URL = ports.mcpUrl;
|
||||
env.NEXT_PUBLIC_KANDEV_MCP_PORT = String(ports.mcpPort);
|
||||
}
|
||||
|
||||
if (production) {
|
||||
(env as Record<string, string>).NODE_ENV = "production";
|
||||
}
|
||||
@@ -127,8 +119,6 @@ export type StartupInfoOptions = {
|
||||
ports: PortConfig;
|
||||
/** Database file path */
|
||||
dbPath?: string;
|
||||
/** Whether to log MCP-related ports */
|
||||
includeMcp?: boolean;
|
||||
/** Log level being used */
|
||||
logLevel?: string;
|
||||
};
|
||||
@@ -137,15 +127,12 @@ export type StartupInfoOptions = {
|
||||
* Logs a unified startup info block to the console.
|
||||
*/
|
||||
export function logStartupInfo(options: StartupInfoOptions): void {
|
||||
const { header, ports, dbPath, includeMcp = false, logLevel } = options;
|
||||
const { header, ports, dbPath, logLevel } = options;
|
||||
console.log(`[kandev] ${header}`);
|
||||
console.log("[kandev] backend port:", ports.backendPort);
|
||||
console.log("[kandev] web port:", ports.webPort);
|
||||
console.log("[kandev] url: http://localhost:" + ports.backendPort);
|
||||
console.log("[kandev] agentctl port:", ports.agentctlPort);
|
||||
if (includeMcp) {
|
||||
console.log("[kandev] mcp port:", ports.mcpPort);
|
||||
console.log("[kandev] mcp url:", ports.mcpUrl);
|
||||
}
|
||||
console.log("[kandev] mcp port:", ports.mcpPort);
|
||||
console.log("[kandev] mcp url:", ports.mcpUrl);
|
||||
if (dbPath) {
|
||||
console.log("[kandev] db path:", dbPath);
|
||||
}
|
||||
|
||||
@@ -121,13 +121,12 @@ export async function runStart({
|
||||
...(debug ? { KANDEV_DEBUG_AGENT_MESSAGES: "true" } : {}),
|
||||
},
|
||||
});
|
||||
const webEnv = buildWebEnv({ ports, includeMcp: true, production: true, debug });
|
||||
const webEnv = buildWebEnv({ ports, production: true, debug });
|
||||
|
||||
logStartupInfo({
|
||||
header: "start mode: using local build",
|
||||
ports,
|
||||
dbPath,
|
||||
includeMcp: true,
|
||||
logLevel,
|
||||
});
|
||||
|
||||
@@ -168,6 +167,6 @@ export async function runStart({
|
||||
});
|
||||
|
||||
await waitForUrlReady(webUrl, webProc, healthTimeoutMs);
|
||||
console.log(`[kandev] web ready at ${webUrl}`);
|
||||
openBrowser(webUrl);
|
||||
console.log("[kandev] ready at " + ports.backendUrl);
|
||||
openBrowser(ports.backendUrl);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user