Created
January 17, 2016 07:14
-
-
Save varavut/1a397c833e5ad7df4940 to your computer and use it in GitHub Desktop.
This file contains hidden or 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'); | |
// Create a server with a host and port | |
const server = new Hapi.Server(); | |
server.connection({ | |
host: 'localhost', | |
port: 3002 | |
}); | |
// Add the route | |
server.route({ | |
method: 'GET', | |
path: '/test', | |
handler: function (request, reply) { | |
let count = Math.round(Math.random() * 30); | |
let results = []; | |
for (let i = 0; i < count; i++) { | |
results.push({ value: Math.round(Math.random() * 100) }); | |
} | |
return reply({ data: results }); | |
} | |
}); | |
// Start the server | |
server.start((err) => { | |
if (err) { | |
throw err; | |
} | |
console.log('Server running at:', server.info.uri); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment