Skip to content

Instantly share code, notes, and snippets.

@nlharri
Last active December 6, 2018 09:51
Show Gist options
  • Save nlharri/261958c8b9b884c0037d7ee146dd8201 to your computer and use it in GitHub Desktop.
Save nlharri/261958c8b9b884c0037d7ee146dd8201 to your computer and use it in GitHub Desktop.
Hapi Tutorial Exercise 8 - Streams
/*
Makemehapi Workshop Exercise 8 Solution
Based on the official solution, but modified a little bit, and changed to work with Cloud9 environemnt.
Official solution:
https://github.com/hapijs/makemehapi/blob/master/exercises/streams/solution/solution.js
License of the official solution: https://github.com/hapijs/makemehapi/blob/master/LICENSE
*/
var Hapi = require('hapi');
var Fs = require('fs');
var Path = require('path');
var Rot13 = require('rot13-transform')
var server = Hapi.Server({
host: process.env.IP,
port: Number(process.argv[2] || process.env.PORT)
});
server.route({
path: '/',
method:'GET',
handler: (request, h) => {
var thisfile = Fs.createReadStream(Path.join(__dirname, 'makemehapi-exercise-8.txt'));
return thisfile.pipe(Rot13());
}
});
const init = async () => {
await server.start();
console.log(`Server running at: ${server.info.uri}`);
};
init();
The Pursuit of Hapi-ness
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment