Experiment with hapijs project structure using glue.
For a more solid hapijs glue example, refer to hapijs/university project.
Coding conventions from hapijs university learning experiment.
Inspiration taken from:
https://github.com/hapijs/university and
https://github.com/npm/newww
git clone https://github.com/zoe-1/glued.git
git branch
View all branches / steps.
### step-7 is the current step. Project uses glue to configure the application.
TLS/SSL is enforced on all routes. Application will not accept non TLS requests,
they are redirected to be https requests.
git checkout template-skeleton
git checkout step-1
* install packages
npm install hapi@latest hoek@latest glue@latest --save
npm install code@latest lab@latest --save-dev
* Make two modules in library.
main and version.
Use glue to load modules. See: ./lib/manifest.json ./lib/index.js * Configure npm start command. * Use Makefile to start application.
git checkout step-2 Testing the application. * use lab and code to execute unit tests. * Test ensure server starts up properly. * Test ensure plugins load properly. * Configure make file and npm to execute tests. * Version plugin has prefix configured. prefix equals "version"
git checkout step-3 Configure tls (Transport Layer Security) encryption * Create tls self signed cert for development server (openssl). * Create configuration script. ./lib/congfig/config.js Store tls cert values in config.js script. * Configure manifest.json file to include tls settings and server. * On live server config file is to we swaped out w/ live settings.
* Make new plugin called "one".
* Configure "one" plugin's path for views, helpers, and partials.
Every plugin can serve html files located in the configured view directory.
view path:
All views use by reply.view() method must be stored in the configured view
directory.
helpersPath:
Helpers scripts used inisde view files are located in the configured helpersPath.
partialsPath:
Partials used by views are stored in the partialsPath.
template engine:
* Configure route "/" which serves an html view file named index.html.
* Configure the "one" plugin to serve static assets. (css,images,js).
index.html view will use assets like css files, image files,
and js files. These static assets are located in the plugins "public" folder.
One of the unique features of hapi is it's plugin structure.
This structure allows static files to be stored inside the plugin.
This allows for better code organization because every plugin's css, image, and js files
are stored inside the plugin itself. Importantly, these static files are accessable across the
hapijs application not just inside the plugin.
* Learning objectives:
* Understand hapi configuration of views, partials, and helpers.
* Understand hapi configuration of static assets: css, images, and js files.
* Learn how to make a route with a hapi plugin.
* Learn how to configure handlebars.
Make index route which utilizes static assets - css, images, and js.
* Learn how to configure a plugins manifest file settings.
* Step-4 configured the "one" plugin's index.html view, now we will add routes
which will handle RESTful requests from the server.
* Make RESTful routes with html views for them:
post - form post POST
get - path params GET
* See below link for more about RESTFUL requests.
http://en.wikipedia.org/wiki/Representational_state_transfer
* tests for the new route
* Learning Objectives
- Learn how to make routes that handle RESTful requests.
- Understand the theory behind RESTful requests.
* Step-4 & 5 showed how to make a plugin ("one") configured to use
html views, style sheets, page specific JavaScript, image includes,
and RESTful routes. These are all features any normal web server
would offer. At this stage, we have hapijs cofigured to work like a
normal webserver.
* Now it is time to add validation of submitted data using joi.
joi is an object schema validation tool we will use to validate
submitted data. In this step we will use joi to validate form
submission (POST requests) and query strings (GET requests).
* Make a plugin named "joi".
* Make a view with an html form which submits specific data to be validated.
* Make a route that handles POST requests from the above form and
uses joi to validate data submitted by the form.
* Make a route named "badstuff" that handles query data submitted by
a link (GET request). This route will also use joi to validate the
data submitted by the GET request.
* Configure joi to establish what kind of data can be submitted.
* Add a new plugin configuration to the manifest.js file for joi plugin.
* Tests made with 100% coverage.
* This step utilizes hapi-auth-cookie plugin
* with a simple login system that works.
* But, I am having trouble with getting 100% coverage in the tests.
* sessions -
* user fingerprint -
* security planning.
* To do
* log output to file. Track performance etc.
localhost:8000
http://localhost:8000/one GET
localhost:8000/joi POST GET
localhost:8000/joi/badstuff GET
localhost:8000/auth POST GET
localhost:8000/auth/loggedin
localhost:8000/auth/logout
handlebars configured
static assets
Each plugin has directories configured for css, image, and js files.