const fs = require('fs'); const apps = []; let nginxConfig = "server {\n\tlisten 7860;\n"; Object.keys(process.env) .filter(key => key.startsWith('SECRET_API_ENDPOINT_')) .forEach(key => { const i = key.split('_').pop(); const workerKey = `SECRET_WORKER_CONCURRENCY_${i}`; const apiEndpoint = process.env[key]; const workerConcurrency = process.env[workerKey]; if (apiEndpoint && workerConcurrency) { apps.push({ name: `app${i}`, script: 'app.js', instances: 1, env: { PORT: 3000 + parseInt(i), API_ENDPOINT: apiEndpoint, WORKER_CONCURRENCY: workerConcurrency } }); // Add an NGINX config for this app nginxConfig += `\tlocation /app${i} {\n\t\tproxy_pass http://localhost:${3000 + parseInt(i)};\n\t}\n`; } }); nginxConfig += "}\n"; const config = { apps }; fs.writeFileSync('ecosystem.config.js', `module.exports = ${JSON.stringify(config, null, 2)};`); fs.writeFileSync('default.conf', nginxConfig);