From cc7f0209d685e96638d2979333ecac564511abf9 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 27 Jun 2014 17:12:25 +0100 Subject: [PATCH 1/2] adds route /nelsonic-proxy to google.com --- friday-participants.json | 3 ++- lib/plugins/nelsonic/index.js | 22 +++++++++++++++++++--- server.js | 4 ++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/friday-participants.json b/friday-participants.json index 4b80c8f..bfbe89f 100644 --- a/friday-participants.json +++ b/friday-participants.json @@ -27,5 +27,6 @@ "davidfoliveira", "pmarques", "gergelyke", - "anarcastanho" + "anarcastanho", + "nelsonic" ] \ No newline at end of file diff --git a/lib/plugins/nelsonic/index.js b/lib/plugins/nelsonic/index.js index 26e7604..87d4a81 100644 --- a/lib/plugins/nelsonic/index.js +++ b/lib/plugins/nelsonic/index.js @@ -6,13 +6,29 @@ var internals = {}; // Defaults internals.defaults = {}; +var mapper = function (request, callback) { + callback(null, 'http://www.google.com/search?q='+request.params.name); +}; + + exports.register = function(plugin, options, next) { + // plugin.route({ + // method: 'GET', + // path: '/nelsonic', + // handler: function(request, reply) { + // reply('don\'t worry, be hapi!'); + // } + // }); + plugin.route({ method: 'GET', - path: '/nelsonic', + path: '/nelsonic-proxy/{name}', handler: function(request, reply) { - reply('don\'t worry, be hapi!'); + reply.proxy({ + redirects:2, + mapUri: mapper + }); } }); @@ -21,5 +37,5 @@ exports.register = function(plugin, options, next) { exports.register.attributes = { name: 'nelsonic', - version: '0.0.0' + version: '0.0.1' }; diff --git a/server.js b/server.js index 8afaab5..1f4d0d2 100644 --- a/server.js +++ b/server.js @@ -1,11 +1,11 @@ var Hapi = require('hapi'); var FridayParticipants = require('./friday-participants.json'); +// console.log(FridayParticipants); var server = Hapi.createServer('0.0.0.0', 8080); - FridayParticipants.forEach(function (participant) { - + // console.log("P:",participant); var participantPlugin = require('./lib/plugins/' + participant); server.pack.register(participantPlugin, function (err) { From 83b101a5fcc6e11fb0ec21e3c565d0fb5246d46f Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 27 Jun 2014 17:34:09 +0100 Subject: [PATCH 2/2] comments out proxy route (to pass array test) --- lib/plugins/nelsonic/index.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/plugins/nelsonic/index.js b/lib/plugins/nelsonic/index.js index 87d4a81..cdbb8a4 100644 --- a/lib/plugins/nelsonic/index.js +++ b/lib/plugins/nelsonic/index.js @@ -13,25 +13,25 @@ var mapper = function (request, callback) { exports.register = function(plugin, options, next) { - // plugin.route({ - // method: 'GET', - // path: '/nelsonic', - // handler: function(request, reply) { - // reply('don\'t worry, be hapi!'); - // } - // }); - plugin.route({ method: 'GET', - path: '/nelsonic-proxy/{name}', + path: '/nelsonic', handler: function(request, reply) { - reply.proxy({ - redirects:2, - mapUri: mapper - }); + reply('don\'t worry, be hapi!'); } }); + // plugin.route({ + // method: 'GET', + // path: '/nelsonic-proxy/{name}', + // handler: function(request, reply) { + // reply.proxy({ + // redirects:2, + // mapUri: mapper + // }); + // } + // }); + next(); };