21 lines
1.1 KiB
JavaScript
21 lines
1.1 KiB
JavaScript
'use strict';
|
|
const path = require('node:path'), { spawn } = require('node:child_process');
|
|
const root = path.resolve(__dirname, '../..'), children = [];
|
|
for (const mode of ['state', 'rednote']) {
|
|
children.push(spawn(process.execPath, [path.join(__dirname, 'fixture-server.cjs')], {
|
|
env: { ...process.env, JUZI_ENTRY_MODE: mode, PORT: mode === 'state' ? '18381' : '18382',
|
|
PUBLIC_BASE_URL: 'http://127.0.0.1:18380/' + mode + '/', JUZI_DATA_ROOT: path.join(root, 'temp/rednote-local-data', mode) },
|
|
stdio: 'inherit'
|
|
}));
|
|
}
|
|
const proxy = require('./proxy.cjs')({ statePort: 18381, rednotePort: 18382 });
|
|
proxy.listen(18380, '127.0.0.1', () => console.log('Samples only: http://127.0.0.1:18380/rednote/ and /state/; no external API calls'));
|
|
let closing = false;
|
|
function stop(code = 0) {
|
|
if (closing) return; closing = true;
|
|
children.forEach(child => { if (child.exitCode == null) child.kill(); });
|
|
proxy.close(() => { process.exitCode = code; });
|
|
}
|
|
children.forEach(child => child.on('exit', code => { if (!closing) stop(code || 1); }));
|
|
process.on('SIGINT', () => stop()); process.on('SIGTERM', () => stop());
|