Skip to content

Commit 77748ae

Browse files
committed
feat(color-api): code v1.3.0
1 parent 771d363 commit 77748ae

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

containers/color-api/src/index.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11
const express = require('express');
22
const os = require('os');
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
const getColor = () => {
7+
let color = process.env.DEFAULT_COLOR;
8+
const filePath = process.env.COLOR_CONFIG_PATH;
9+
10+
if (filePath) {
11+
try {
12+
const colorFromFile = fs.readFileSync(path.resolve(filePath), 'utf8');
13+
14+
color = colorFromFile.trim();
15+
} catch (error) {
16+
console.error(`Failed to read contents of ${filePath}`);
17+
console.error(error);
18+
}
19+
}
20+
21+
return color || 'blue';
22+
};
323

424
const app = express();
525
const port = 80;
6-
const color = 'blue';
26+
const color = getColor();
727
const hostname = os.hostname();
828

929
const delay_startup = process.env.DELAY_STARTUP === 'true';

0 commit comments

Comments
 (0)