Show it a video you love. Get a new video in the same style. An AI crew (Claude Code or Codex) plans, builds and reviews it with you.
JavaScript 2d-animationai-agentsai-videoanimationclaude-codecodexmulti-agentstyle-transfervideo-generation
feat: add /api/health and open the browser once the server answers
LouieTang5d76b4fd2c87
diff --git a/app/server/health.test.ts b/app/server/health.test.tsnew file mode 100644index 0000000..af2bf43--- /dev/null+++ b/app/server/health.test.ts@@ -0,0 +1,26 @@+// GET /api/health: what start.bat / start.sh wait for before opening the browser.+// Starts the real server on a spare port against a throwaway projects folder; PYTHON is set so startup doesn't go+// looking for an interpreter. No agent is started.+import { after, test } from 'node:test';+import assert from 'node:assert/strict';+import { spawn } from 'node:child_process';+import { mkdtempSync, rmSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';++const TMP = mkdtempSync(join(tmpdir(), 'reelmimic-test-'));+const PORT = 20000 + Math.floor(Math.random() * 20000);+const server = spawn(process.execPath, [join(import.meta.dirname, 'index.ts')], { env: { ...process.env, PORT: String(PORT), REELMIMIC_PROJECTS: TMP, PYTHON: 'reelmimic-no-such-python' }, stdio: 'ignore' });+after(() => { server.kill(); rmSync(TMP, { recursive: true, force: true }); });++const health = async () => {+ for (let i = 0; i < 100; i++) { try { return await fetch(`http://127.0.0.1:${PORT}/api/health`); } catch { await new Promise((r) => setTimeout(r, 100)); } }+ throw new Error('server did not start');+};++test('answers { ok: true } once the server is listening', async () => {+ const r = await health();+ assert.equal(r.status, 200);+ assert.match(r.headers.get('content-type') || '', /^application\/json/);+ assert.deepEqual(await r.json(), { ok: true });+});diff --git a/app/server/index.ts b/app/server/index.tsindex 2efdf64..977e7ae 100644--- a/app/server/index.ts+++ b/app/server/index.ts@@ -25,6 +25,8 @@ const safeName = (n: string) => n.replace(/[\\/:*?"<>|]+/g, '_').slice(0, 120);const isUrl = (s: string | undefined) => /^https?:\/\/\S+$/i.test((s || '').trim());const guard = (res: Response, id: string) => { if (!/^[\w-]+$/.test(id) || !existsSync(join(J.dirOf(id), 'job.json'))) { res.status(404).json({ error: 'no such project' }); return false; } return true; };+// Answers as soon as the server is listening: start.bat / start.sh poll it before opening the browser+app.get('/api/health', (req, res) => res.json({ ok: true }));let AGENTS: AgentStatus | null = null;app.get('/api/agents', (req, res) => { AGENTS = AGENTS || agentStatus(); res.json(AGENTS); });app.get('/api/projects', (req, res) => res.json(J.listJobs()));diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.mdindex ba0d749..e049ec3 100644--- a/docs/ARCHITECTURE.md+++ b/docs/ARCHITECTURE.md@@ -136,6 +136,7 @@ builder (kept across fix rounds); reviewers always start fresh.| Method | Path | Purpose ||---|---|---|+| GET | `/api/health` | `{ ok: true }` once the server is listening (`start.bat` / `start.sh` wait for it before opening the browser) || GET | `/api/agents` | detect installed agent CLIs || GET/POST | `/api/projects` | list / create (multipart: reference or url, brief, agent, lang, inputs) || GET | `/api/projects/:id` | project snapshot (everything the web app needs) |diff --git a/docs/zh-CN/ARCHITECTURE.md b/docs/zh-CN/ARCHITECTURE.mdindex 556ebff..2c9e972 100644--- a/docs/zh-CN/ARCHITECTURE.md+++ b/docs/zh-CN/ARCHITECTURE.md@@ -119,6 +119,7 @@ projects/<id>/| 方法 | 路径 | 用途 ||---|---|---|+| GET | `/api/health` | 服务器开始接受连接后回 `{ ok: true }`(`start.bat`/`start.sh` 等到它响应才打开浏览器) || GET | `/api/agents` | 侦测已安装的 agent CLI || GET/POST | `/api/projects` | 列表/创建(multipart:reference 或 url、brief、agent、lang、inputs) || GET | `/api/projects/:id` | 项目快照(网站需要的所有数据) |diff --git a/docs/zh-TW/ARCHITECTURE.md b/docs/zh-TW/ARCHITECTURE.mdindex fb0619b..dcc854a 100644--- a/docs/zh-TW/ARCHITECTURE.md+++ b/docs/zh-TW/ARCHITECTURE.md@@ -119,6 +119,7 @@ projects/<id>/| 方法 | 路徑 | 用途 ||---|---|---|+| GET | `/api/health` | 伺服器開始接受連線後回 `{ ok: true }`(`start.bat`/`start.sh` 等到它回應才開瀏覽器) || GET | `/api/agents` | 偵測已安裝的 agent CLI || GET/POST | `/api/projects` | 列表/建立(multipart:reference 或 url、brief、agent、lang、inputs) || GET | `/api/projects/:id` | 專案快照(網站需要的所有資料) |diff --git a/start.bat b/start.batindex 006ddfa..1e3f1fb 100644--- a/start.bat+++ b/start.bat@@ -3,5 +3,7 @@ rem ReelMimic - build the UI if needed and start the server on http://localhost:cd /d "%~dp0app"if not exist node_modules call npm installif not exist dist call npm run build-start "" http://localhost:4318+rem open the browser once the server answers /api/health (a cold start can take a while), checking in the background+rem so the server keeps this window; 20 tries is about a minute (Windows takes ~2 s to refuse a connection, ping waits 1 s)+start "" /b cmd /d /q /c "(for /l %%i in (1,1,20) do (curl -sf -m 2 http://localhost:4318/api/health >nul 2>&1 && (start "" http://localhost:4318 & exit) || ping -n 2 127.0.0.1 >nul)) & echo ReelMimic is not answering on http://localhost:4318: see the messages above, or open it yourself once it is up."node server\index.tsdiff --git a/start.sh b/start.shindex bf064b7..977e8b9 100644--- a/start.sh+++ b/start.sh@@ -4,5 +4,9 @@ set -ecd "$(dirname "$0")/app"[ -d node_modules ] || npm install[ -d dist ] || npm run build-( sleep 2; (command -v xdg-open >/dev/null && xdg-open http://localhost:4318) || (command -v open >/dev/null && open http://localhost:4318) || true ) &+# open the browser once the server answers /api/health (a cold start can take a while); give up after a minute+( SECONDS=0; until curl -sf -m 2 http://localhost:4318/api/health >/dev/null 2>&1; do+ [ $SECONDS -lt 60 ] || { echo "ReelMimic is not answering on http://localhost:4318: see the messages above, or open it yourself once it is up." >&2; exit 1; }+ sleep 1; done+ (command -v xdg-open >/dev/null && xdg-open http://localhost:4318) || (command -v open >/dev/null && open http://localhost:4318) || true ) &exec node server/index.ts