Skip to content

Instantly share code, notes, and snippets.

@varavut
Created January 17, 2016 07:14
Show Gist options
  • Save varavut/1a397c833e5ad7df4940 to your computer and use it in GitHub Desktop.
Save varavut/1a397c833e5ad7df4940 to your computer and use it in GitHub Desktop.
'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