39474-vm/scripts/run-api.mjs
2026-04-04 22:08:49 +05:00

32 lines
1022 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { spawn } from 'node:child_process';
import { existsSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const root = path.join(__dirname, '..');
const backend = path.join(root, 'backend');
const win = process.platform === 'win32';
const pyName = win ? 'python.exe' : 'python';
const candidates = [
path.join(root, '.venv', win ? 'Scripts' : 'bin', pyName),
path.join(root, 'backend', 'venv', win ? 'Scripts' : 'bin', pyName),
];
const python = candidates.find((p) => existsSync(p));
if (!python) {
console.error(
'Не найден Python в .venv или backend\\venv. Создайте venv и: pip install -r backend/requirements.txt',
);
process.exit(1);
}
const child = spawn(
python,
['-m', 'uvicorn', 'app.main:app', '--reload', '--host', '127.0.0.1', '--port', '8000'],
{ cwd: backend, stdio: 'inherit', shell: false },
);
child.on('exit', (code) => process.exit(code ?? 0));