-
-
Save nlharri/261958c8b9b884c0037d7ee146dd8201 to your computer and use it in GitHub Desktop.
Hapi Tutorial Exercise 8 - Streams
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
/* | |
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(); |
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
The Pursuit of Hapi-ness |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment