Skip to content

Instantly share code, notes, and snippets.

@tomfa
Last active September 4, 2017 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomfa/6500ed1e1c4076b5e6ec7c534b7c52ba to your computer and use it in GitHub Desktop.
Save tomfa/6500ed1e1c4076b5e6ec7c534b7c52ba to your computer and use it in GitHub Desktop.
Small script that serves static files in hubot
// index.html up at localhost:8080/status
//
// requirements: mime (npm install mime --save)
const path = require('path');
const fs = require('fs');
var mime = require('mime');
const serveFile = filePath => (req, res) => {
const fullPath = path.join(__dirname, filePath);
fs.readFile(fullPath, {encoding: 'utf-8'}, function(err, data){
if (!err) {
res.writeHead(200, {'Content-Type': mime.lookup(fullPath)});
res.write(data);
res.end();
} else {
console.log(err);
}
});
};
function hubotFunctions(robot) {
robot.router.get('/status', serveFile('../public/index.html'));
}
module.exports = hubotFunctions;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment