Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. 'use strict';
  2.  
  3. //load Hapi
  4. const Hapi = require('hapi');
  5. //load plugin 'inert'
  6. const inert = require('inert');
  7.  
  8. //create new server
  9. const server = new Hapi.Server();
  10.  
  11. //connect server
  12. server.connection({
  13. port: 2000,
  14. host: 'localhost'
  15. });
  16.  
  17. //handler
  18. const test = function (request, reply) {
  19. var parts = {
  20. temperature: request.params.temperature,
  21. humidity: request.params.humidity
  22. };
  23. return reply(parts)
  24. };
  25.  
  26. //jsonp send params to firebase
  27. server.route({
  28. method: 'GET',
  29. path: '/{temperature}/{humidity}/',
  30. config: {
  31. handler: test,
  32. jsonp: 'callback'
  33. }
  34. });
  35.  
  36. //serving static
  37. server.register(inert, (err) => {
  38. if (err) {
  39. throw err;
  40. }
  41. server.route({
  42. method: 'GET',
  43. path: '/test',
  44. handler: function (request, reply) {
  45. reply.file('./public/index.html');
  46. }
  47. });
  48. });
  49.  
  50. //start server and print to console for checking
  51. server.start(function () {
  52. console.log("SERVER STARTED: ", server.info.uri);
  53. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement