Spaces:
Runtime error
Runtime error
File size: 1,033 Bytes
13d6914 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
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); |