Skip to content

Consolidate dual-server setup into single Express server; fix binary auto-detection#5

Merged
lmangani merged 2 commits intomainfrom
copilot/simplify-server-architecture
Mar 7, 2026
Merged

Consolidate dual-server setup into single Express server; fix binary auto-detection#5
lmangani merged 2 commits intomainfrom
copilot/simplify-server-architecture

Conversation

Copy link
Contributor

Copilot AI commented Mar 7, 2026

Two issues: start-all.sh launched both a Vite dev server (5173) and an Express API server (3001), forcing users to juggle two ports. Additionally, .env.example hardcoded placeholder ACESTEP_BIN=/path/to/acestep-generate, triggering a startup warning on every fresh clone even though the server already auto-detects binaries from ./bin/.

Bug fix: APP_ROOT wrong depth

server/src/config/index.ts lived at server/src/config/ but resolved APP_ROOT with '../..', landing at server/ instead of the repo root. Binary detection was silently checking server/bin/ace-qwen3 (never exists) instead of bin/ace-qwen3 (where build.sh installs them).

// Before — resolves to <repo>/server/ (wrong)
const APP_ROOT = path.resolve(__dirname, '../..');

// After — resolves to <repo>/ (correct)
const APP_ROOT = path.resolve(__dirname, '../../..');

Single-server: Express serves the built frontend

Added SPA static serving to server/src/index.ts. index.html is read once at startup and served from memory for all unmatched non-API routes:

const DIST_DIR = path.join(__dirname, '../../dist');
if (existsSync(DIST_DIR)) {
  app.use(express.static(DIST_DIR));
  const indexHtml = readFileSync(path.join(DIST_DIR, 'index.html'), 'utf-8');
  app.get('*', (req, res, next) => {
    if (req.path.startsWith('/api/') || req.path.startsWith('/audio/') || ...) return next();
    res.type('html').send(indexHtml);
  });
}

start-all.sh / start-all.bat

  • Runs npm run build before starting the server
  • Starts a single Node.js process; no Vite dev server
  • Single URL shown: http://localhost:3001
  • PID written to logs/server.pid; stop-all.sh handles both new and legacy PID files

Config / env cleanup

  • .env.example and server/.env.example: removed ACESTEP_BIN, ACESTEP_MODEL, FRONTEND_URL, VITE_API_URL placeholders — all auto-detected
  • server/src/config/index.ts: frontendUrl defaults to http://localhost:<PORT> (same origin); extracted resolvedPort constant to eliminate the duplicated '3001' literal
  • setup.sh: "Next steps" no longer instructs users to manually edit .env
  • README.md: updated quick start (3 steps, not 4), usage table, config reference, troubleshooting

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

- Fix APP_ROOT depth in server/src/config/index.ts (was server/ not repo root)
- Add built frontend serving and SPA fallback to Express server
- start-all.sh: build frontend, start single server on port 3001
- .env.example: remove placeholder ACESTEP_BIN/ACESTEP_MODEL/FRONTEND_URL
- setup.sh: fix misleading 'edit .env' next steps output
- stop-all.sh: use logs/server.pid, keep legacy PIDs for upgrade compat
- start-all.bat: rewrite Windows script for single-server approach
- README.md: update quick start, usage, config, troubleshooting docs

Co-authored-by: lmangani <1423657+lmangani@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor to use a single server for both API and UI Consolidate dual-server setup into single Express server; fix binary auto-detection Mar 7, 2026
@lmangani lmangani marked this pull request as ready for review March 7, 2026 16:03
@lmangani lmangani merged commit 7d7cdd7 into main Mar 7, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants