×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: user7d204
Added: Dec 31, 2016 11:03 PM
Views: 7
  1. 'use strict';
  2.  
  3. const Hapi = require('hapi');
  4.  
  5. // Create a server with a host and port
  6. const server = new Hapi.Server();
  7. server.connection({
  8.     host: 'localhost',
  9.     port: 3000
  10. });
  11.  
  12. // Add the route
  13. server.route({
  14.     method: 'GET',
  15.     path: '/',
  16.     handler: function (request, reply) {
  17.         reply('Hello, world!');
  18.     }
  19. });
  20.  
  21. server.route({
  22.     method: 'GET',
  23.     path: '/{name}',
  24.     handler: function (request, reply) {
  25.         reply('Hello, ' + encodeURIComponent(request.params.name) + '!');
  26.     }
  27. });
  28.  
  29. // Start the server
  30. server.start((err) => {
  31.  
  32.     if (err) {
  33.         throw err;
  34.     }
  35.     console.log(`Server running at: ${server.info.uri}`);
  36. });