Files
Art-gallery/scripts/dev-web.js
T

49 lines
1.4 KiB
JavaScript

/**
* Start public dev stack: Vite on :5173, API on :3451 (or PORT from .env).
* Keenetic: devgallery.mysuperlab.netcraze.pro → 192.168.10.70:5173
*/
const { spawn } = require('child_process');
const path = require('path');
require('dotenv').config({ path: path.join(__dirname, '..', '.env') });
const apiPort = process.env.DEV_API_PORT || process.env.PORT || '3451';
const vitePort = process.env.DEV_WEB_PORT || '5173';
const env = {
...process.env,
PORT: apiPort,
APP_ENV: process.env.APP_ENV || 'dev',
IMAGE_TAG: process.env.IMAGE_TAG || 'dev-local',
};
function run(label, command, args, cwd) {
const child = spawn(command, args, {
cwd,
env,
shell: true,
stdio: 'inherit',
});
child.on('exit', (code) => {
if (code && code !== 0) {
console.error(`${label} exited with code ${code}`);
}
});
return child;
}
console.log(`Gallery dev:web — UI http://0.0.0.0:${vitePort} API http://127.0.0.1:${apiPort}`);
console.log(`Set PUBLIC_URL=http://devgallery.mysuperlab.netcraze.pro in .env for Keenetic`);
const api = run('API', 'npx', ['nodemon', 'server/index.js'], path.join(__dirname, '..'));
const client = run('Vite', 'npm', ['run', 'dev', '--prefix', 'client', '--', '--port', vitePort, '--host'], path.join(__dirname, '..'));
function shutdown() {
api.kill('SIGTERM');
client.kill('SIGTERM');
process.exit(0);
}
process.on('SIGINT', shutdown);
process.on('SIGTERM', shutdown);