Created
April 5, 2016 16:49
-
-
Save mtharrison/2889ba6d63815733dae8602f0728bb76 to your computer and use it in GitHub Desktop.
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
'use strict'; | |
const Hapi = require('hapi'); | |
const server = new Hapi.Server(); | |
server.connection({ port: 4000 }); | |
server.auth.scheme('payload', function (server, options) { | |
return { | |
authenticate: function (request, reply) { | |
return reply.continue({ credentials: {} }); | |
}, | |
payload: function (request, reply) { | |
let i = 0; | |
const interval = setInterval(() => { | |
console.log(++i); | |
}, 1000); | |
setTimeout(() => { | |
clearInterval(interval); | |
reply.continue(); | |
}, 5000); | |
}, | |
options: { | |
payload: true | |
} | |
}; | |
}); | |
server.auth.strategy('payload', 'payload'); | |
server.route({ | |
config: { | |
auth: 'payload' | |
}, | |
method: 'POST', | |
path: '/', | |
handler: function (request, reply) { | |
reply('ok'); | |
} | |
}); | |
server.start((err) => { | |
if (err) { | |
throw err; | |
} | |
console.log('Server started!'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment