const { execSync } = require('child_process'); const config = { port: parseInt(process.env.PORT, 10) || 8888, baseDomain: process.env.BASE_DOMAIN || '', projectPortStart: parseInt(process.env.PROJECT_PORT_START, 10) || 9000, projectPortEnd: parseInt(process.env.PROJECT_PORT_END, 10) || 9100, projectBindAddress: process.env.PROJECT_BIND_ADDRESS || '127.0.0.1', useNginx: process.env.USE_NGINX || 'auto', nginxConfigDir: process.env.NGINX_CONFIG_DIR || './nginx/sites-enabled', nginxTemplatePath: process.env.NGINX_TEMPLATE_PATH || './server/templates/nginx', nginxReloadCmd: process.env.NGINX_RELOAD_CMD || 'nginx -s reload', nginxTestCmd: process.env.NGINX_TEST_CMD || 'nginx -t', nginxAvailable: null, actualMode: null, checkNginxMode() { if (this.actualMode !== null) { return this.actualMode; } if (this.useNginx === true || this.useNginx === 'true') { this.nginxAvailable = true; this.actualMode = 'nginx'; return 'nginx'; } if (this.useNginx === false || this.useNginx === 'false') { this.nginxAvailable = false; this.actualMode = 'multiport'; return 'multiport'; } if (this.useNginx === 'auto') { this.nginxAvailable = this._testNginxAvailable(); this.actualMode = this.nginxAvailable ? 'nginx' : 'multiport'; return this.actualMode; } this.nginxAvailable = this._testNginxAvailable(); this.actualMode = this.nginxAvailable ? 'nginx' : 'multiport'; return this.actualMode; }, _testNginxAvailable() { try { execSync('nginx -v 2>&1', { stdio: 'pipe' }); return true; } catch (error) { return false; } }, isNginxMode() { if (this.actualMode === null) { this.checkNginxMode(); } return this.actualMode === 'nginx'; }, getProjectUrl(projectId, port) { if (this.isNginxMode()) { const baseUrl = this.getBaseUrl(); return `${baseUrl}/project/${projectId}/`; } const domain = this.baseDomain || 'localhost'; return `http://${domain}:${port}`; }, getBaseUrl() { if (this.baseDomain) { return `http://${this.baseDomain}`; } return `http://localhost:${this.port}`; }, isProduction() { return !!this.baseDomain; } }; module.exports = config;