Spaces:
Runtime error
Runtime error
Commit
·
13d6914
1
Parent(s):
93293f1
Create generate-config.js
Browse files- generate-config.js +37 -0
generate-config.js
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const fs = require('fs');
|
2 |
+
const apps = [];
|
3 |
+
let nginxConfig = "server {\n\tlisten 7860;\n";
|
4 |
+
|
5 |
+
Object.keys(process.env)
|
6 |
+
.filter(key => key.startsWith('SECRET_API_ENDPOINT_'))
|
7 |
+
.forEach(key => {
|
8 |
+
const i = key.split('_').pop();
|
9 |
+
const workerKey = `SECRET_WORKER_CONCURRENCY_${i}`;
|
10 |
+
const apiEndpoint = process.env[key];
|
11 |
+
const workerConcurrency = process.env[workerKey];
|
12 |
+
|
13 |
+
if (apiEndpoint && workerConcurrency) {
|
14 |
+
apps.push({
|
15 |
+
name: `app${i}`,
|
16 |
+
script: 'app.js',
|
17 |
+
instances: 1,
|
18 |
+
env: {
|
19 |
+
PORT: 3000 + parseInt(i),
|
20 |
+
API_ENDPOINT: apiEndpoint,
|
21 |
+
WORKER_CONCURRENCY: workerConcurrency
|
22 |
+
}
|
23 |
+
});
|
24 |
+
|
25 |
+
// Add an NGINX config for this app
|
26 |
+
nginxConfig += `\tlocation /app${i} {\n\t\tproxy_pass http://localhost:${3000 + parseInt(i)};\n\t}\n`;
|
27 |
+
}
|
28 |
+
});
|
29 |
+
|
30 |
+
nginxConfig += "}\n";
|
31 |
+
|
32 |
+
const config = {
|
33 |
+
apps
|
34 |
+
};
|
35 |
+
|
36 |
+
fs.writeFileSync('ecosystem.config.js', `module.exports = ${JSON.stringify(config, null, 2)};`);
|
37 |
+
fs.writeFileSync('default.conf', nginxConfig);
|