├── index.js ├── lib ├── views │ ├── layout.hbs │ └── partials │ │ └── main.hbs └── index.js ├── .gitignore ├── README.md ├── package.json └── LICENSE /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | module.exports = require('./lib'); -------------------------------------------------------------------------------- /lib/views/layout.hbs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Reverse proxy hapi client 6 | 7 | 8 | {{> main}} 9 | 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # node-waf configuration 11 | .lock-wscript 12 | 13 | # Compiled binary addons (http://nodejs.org/api/addons.html) 14 | build/Release 15 | 16 | # Dependency directory 17 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 18 | node_modules 19 | 20 | .DS_Store 21 | -------------------------------------------------------------------------------- /lib/views/partials/main.hbs: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | {{#each data}} 5 |
id: {{id}}
6 |
FirstName: {{fname}}
7 |
LastName: {{lname}}
8 |
Phone: {{tel}}
9 |
Address: {{address}}
10 |
City: {{city}}
11 |
State: {{state}}
12 |
Zip: {{zip}}
13 |
14 | {{/each}} 15 |
16 |
17 |
-------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hapi-client-proxy 2 | Creating a reverse proxy pattern for client to hapi 3 | 4 | # Concept 5 | To funnel requests from the client(browser) through hapi(nodejs) to an endpoint. 6 | 7 | While still using hapi to render templates :smirk: 8 | 9 | So all endpoint requests are made by hapi. 10 | 11 | 12 | ### Todo 13 | - Create proxy 14 | - Create templates (for benchmark load) 15 | - Benchmark results 16 | 17 | ### Packages used 18 | - [Rest](https://github.com/cujojs/rest) 19 | - [Hapi](https://github.com/hapijs/hapi) 20 | - [PM2](https://github.com/Unitech/PM2) 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hapi-client-proxy", 3 | "description": "Creating a reverse proxy pattern for client to hapi ", 4 | "version": "1.0.0", 5 | "author": "David Chase ", 6 | "bugs": { 7 | "url": "https://github.com/davidchase/hapi-client-proxy/issues" 8 | }, 9 | "homepage": "https://github.com/davidchase/hapi-client-proxy#readme", 10 | "keywords": [ 11 | "hapi" 12 | ], 13 | "license": "MIT", 14 | "main": "index.js", 15 | "private": true, 16 | "repository": { 17 | "type": "git", 18 | "url": "git+https://github.com/davidchase/hapi-client-proxy.git" 19 | }, 20 | "scripts": { 21 | "test": "test" 22 | }, 23 | "dependencies": { 24 | "handlebars": "^3.0.2", 25 | "hapi": "^8.4.0", 26 | "pm2": "^0.12.12", 27 | "rest": "^1.3.1" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 David Chase 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var Hapi = require('hapi'); 3 | var rest = require('rest'); 4 | var server = new Hapi.Server(); 5 | var internals = {}; 6 | 7 | internals.url = 'http://www.filltext.com/?rows=100&id={index}&fname={firstName}&lname={lastName}' + 8 | '&tel={phone|format}&address={streetAddress}&city={city}&state={usState|abbr}&zip={zip}'; 9 | 10 | internals.mime = require('rest/interceptor/mime'); 11 | internals.errorCode = require('rest/interceptor/errorCode'); 12 | internals.client = rest.wrap(internals.mime).wrap(internals.errorCode); 13 | internals.handlerFn = function handlerFn(request, reply) { 14 | internals 15 | .client({ 16 | path: internals.url 17 | }) 18 | .then(function(response) { 19 | reply.view('layout', { 20 | data: response.entity 21 | }) 22 | }) 23 | .catch(function(err) { 24 | console.log('oopps', err); 25 | }); 26 | }; 27 | 28 | server 29 | .connection({ 30 | host: 'localhost', 31 | port: 8000 32 | }) 33 | .route({ 34 | method: 'GET', 35 | path: '/', 36 | handler: internals.handlerFn 37 | }); 38 | 39 | server.views({ 40 | engines: { 41 | hbs: require('handlebars') 42 | }, 43 | relativeTo: __dirname, 44 | path: './views', 45 | layoutPath: './views/layout', 46 | partialsPath: './views/partials' 47 | }); 48 | 49 | server.start(function() { 50 | console.log('Server running at:', server.info.uri); 51 | }); --------------------------------------------------------------------------------