Created
June 8, 2015 15:53
-
-
Save joernroeder/e86a3882360497c828f9 to your computer and use it in GitHub Desktop.
node vagrant, docker test app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'), | |
express = require('express'), | |
app = express(), | |
redis = require('redis').createClient( | |
process.env.REDIS_PORT_6379_TCP_PORT || 6379, | |
process.env.REDIS_PORT_6379_TCP_ADDR || '127.0.0.1', | |
{} | |
), | |
server = require('http').createServer(app); | |
var getFiles = function () { | |
var files = fs.readdirSync('/foo'); | |
var data = {}; | |
files.forEach(function (file) { | |
var path = '/foo/' + file; | |
if (fs.statSync(path).isFile(path)) { | |
data[file] = fs.readFileSync(path, { encoding: 'utf8' }); | |
} | |
else { | |
data[file] = 'Not a File!'; | |
} | |
}); | |
return data; | |
}; | |
app.get('/', function(req, res) { | |
res.json({ | |
status: redis ? "ok" : "not ok", | |
files: getFiles() | |
}); | |
}); | |
var port = process.env.HTTP_PORT || 5000; | |
server.listen(port); | |
console.log('Listening on port ' + port); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment