Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- //load Hapi
- const Hapi = require('hapi');
- //load plugin 'inert'
- const inert = require('inert');
- //create new server
- const server = new Hapi.Server();
- //connect server
- server.connection({
- port: 2000,
- host: 'localhost'
- });
- //handler
- const test = function (request, reply) {
- var parts = {
- temperature: request.params.temperature,
- humidity: request.params.humidity
- };
- return reply(parts)
- };
- //jsonp send params to firebase
- server.route({
- method: 'GET',
- path: '/{temperature}/{humidity}/',
- config: {
- handler: test,
- jsonp: 'callback'
- }
- });
- //serving static
- server.register(inert, (err) => {
- if (err) {
- throw err;
- }
- server.route({
- method: 'GET',
- path: '/test',
- handler: function (request, reply) {
- reply.file('./public/index.html');
- }
- });
- });
- //start server and print to console for checking
- server.start(function () {
- console.log("SERVER STARTED: ", server.info.uri);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement