-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathserver.js
34 lines (27 loc) · 1.05 KB
/
server.js
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
var http = require("http"),
fs = require("fs"),
vaultDir = "/application/vault/",
showVault = process.env.SHOW_VAULT,
vaultFiles = process.env.VAULT_FILES,
vaultSecret = process.env.SECRET_KEY,
files = [],
port = 8888;
function handleRequest(req, res) {
res.writeHead(200, {"Content-type":"text/html"});
res.write("Hello, World! This is Node.js app v100.");
// Only show Vault files if the SHOW_VAULT KV is set to true in Consul
if (fs.existsSync(vaultDir) && showVault && (showVault.toUpperCase() === "TRUE" || showVault === "1")) {
files = fs.readdirSync(vaultDir);
for (var i = 0; i < files.length; i++) {
file = files[i];
// Only show this file if included in the VAULT_FILES KV in Consul
if (vaultFiles && vaultFiles.indexOf(file) > -1) {
res.write(fs.readFileSync(vaultDir + file, "binary"));
}
}
}
res.end();
}
http.createServer(handleRequest).listen(port);
console.log("Static file server running at\n => http://localhost:" + port);
console.log("\nVault secret: " + vaultSecret);