Skip to content

Commit 3d2c4c3

Browse files
heqikaicursoragent
andcommitted
fix(desktop): do not attach to dev API server on port 3847
Release builds were reusing any healthy :3847 listener (e.g. npm run dev:desktop), which serves API only and shows "Cannot GET /". Spawn the bundled server exclusively and error when the port is already taken. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent a19795a commit 3d2c4c3

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ Then open again, or right-click the app → **Open** the first time. (Baidu Netd
255255

256256
**Install (Windows):** run the setup `.exe` and follow the wizard.
257257

258-
Requires **git** on `PATH` on both platforms.
258+
Requires **git** on `PATH` on both platforms. **Do not run `npm run dev:desktop` while using the installed app** — both use port 3847; the dev server is API-only and causes a blank `Cannot GET /` page.
259259

260260
**Runtime data:** `~/Library/Application Support/CodeDelta` (macOS) · `%APPDATA%\CodeDelta` (Windows)
261261

apps/desktop/src-tauri/src/server.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,24 @@ fn wait_for_health(timeout: Duration) -> bool {
140140
}
141141

142142
pub fn start(app: &AppHandle) -> Result<(), String> {
143-
if health_ok() {
144-
return Ok(());
145-
}
146-
147143
if cfg!(debug_assertions) {
148-
if wait_for_health(Duration::from_secs(90)) {
144+
if health_ok() {
149145
return Ok(());
150146
}
151147
return Err(
152148
"CodeDelta API is not running on port 3847. Start it with `npm run dev:codedelta` or use `npm run dev:desktop` from the repo root.".into(),
153149
);
154150
}
155151

152+
// Production must spawn the bundled server. Do not attach to a dev API on :3847
153+
// (e.g. `npm run dev:desktop`) — it serves API only and shows "Cannot GET /".
154+
if health_ok() {
155+
let hint = port_in_use_hint().unwrap_or_default();
156+
return Err(format!(
157+
"Port {API_PORT} is already in use. Quit `npm run dev:desktop` or any other CodeDelta/dev server, then reopen the app.\n{hint}"
158+
));
159+
}
160+
156161
let mut child = spawn_bundled(app)?;
157162
if wait_for_health(Duration::from_secs(45)) {
158163
let mut guard = SERVER_CHILD.lock().map_err(|e| e.to_string())?;

packages/codedelta-server/src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ export function resolveCacheRoot(): string | undefined {
2929
if (env) {
3030
return path.isAbsolute(env) ? env : path.resolve(process.cwd(), env);
3131
}
32-
if (process.env.CODEDELTA_DESKTOP === '1' && process.platform === 'darwin') {
33-
return path.join(os.homedir(), 'Library', 'Application Support', 'CodeDelta');
32+
if (process.env.CODEDELTA_DESKTOP === '1') {
33+
const base =
34+
process.platform === 'darwin'
35+
? path.join(os.homedir(), 'Library', 'Application Support', 'CodeDelta')
36+
: process.env.APPDATA
37+
? path.join(process.env.APPDATA, 'CodeDelta')
38+
: path.join(os.homedir(), '.codedelta');
39+
return base;
3440
}
3541
return undefined;
3642
}
@@ -50,6 +56,7 @@ export function createApp(options: CreateAppOptions = {}) {
5056
status: 'ok',
5157
product: 'CodeDelta',
5258
gitAvailable,
59+
servesUi: Boolean(options.staticRoot),
5360
});
5461
});
5562

0 commit comments

Comments
 (0)