Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Glue and HTML views #136

Closed
zoe-1 opened this issue May 22, 2015 · 16 comments · Fixed by #137
Closed

Glue and HTML views #136

zoe-1 opened this issue May 22, 2015 · 16 comments · Fixed by #137
Milestone

Comments

@zoe-1
Copy link
Contributor

zoe-1 commented May 22, 2015

We transitioned to hapijs university.

For details about this change see:

Let's keep our project going! This is community learning which means much of the learning will be
horizontal and not just vertical! Make your contribution, ask questions, give advice (review others code) , share your thoughts about our project's direction and let's push each other to keep growing :-)

The Assignment

  • Refactor the application to use the hapijs server composer hapijs / glue.
    Glue should be used to load "version" and "private" plugins.
    Here is a helpful resource from the Glue project: Sample Manifest JSON object .
  • Create a plugin called "home":
  • This plugin should contain one endpoint called "home".
  • Configure the plugin to use handlebars template rendering engine to render html templates.
  • Configure this plugin to serve html view files and make the home endpoint render an html page/template named home.
  • Configure the home plugin to find view files in a directory named "views" located in
    the root path of the application. For now, just make html pages for view files (no .hbs files).
  • The view directory should contain one html template named home.html.

    When viewed in a browser, the home.html template should display the path to this view file from the root of our project.
  • In the end, the application should have thee endpoints. One called: "home",
    the other called "version", and one called "private". Each point is located in it's own plugin
    which glue composes when the server starts up.
  • Ensure 100% test coverage.
  • Refactor project to meet new requirements Repo style cleanup hapi-contrib#31.
  • Remove Makefile and switch to using npm scripts (see hapi package.json)
  • Remove root index.js (point package.json to lib/index.js)
  • Replace package.json licenses array with single license key and "BSD-3-Clause" value
  • Update code style to stop putting functions on single line (new lab will error on that lint warning)
  • An extra challenge, after doing the above, refactor hapi-auth-basic registration code:
    • Refactor the application to load hapi-auth-basic plugin using glue's manifest file.
    • Remove hapi-auth-basic plugin registration code from the private.js file.
    • private.js plugins' functionality will not change. We are just moving where the
      hapi-auth-basic plugin is registered.
    • Configure Glue to load hapi-auth-basic plugin and make a file dedicated to register the hapi-auth-basic strategy.
      Glue will reference this file in the manifest file to load the plugin.
    • While making the assignment, there was discussion about why not to make this change. See: The Discussion for details.
      But, I encourage everyone to try it. Doing this exercise will help you get to know Glue and hapijs' auth plugin design better ;-)
      If you get stuck here, we will work together to make it work!

Assignment Due May 30th

What is coming next?

  • adding static assets like css, images, js files.
  • validation with joi
  • sessions and authentication with hapi-auth-cookie
  • See "What we are going to build?" section in the README https://github.com/hapijs/university for the big picture plan.
  • If you have suggestions for issues to study please make them!
    Cheers!
@zoe-1 zoe-1 added this to the 0.0.5 milestone May 22, 2015
@ghost
Copy link

ghost commented May 24, 2015

First thanks that these lessons are back again.

Now the first question :

Are these (https://github.com/hapijs/glue/tree/master/test) good examples how to test things with glue and lab. I have to rewrite all the former test now :(

Roelof

@ghost
Copy link

ghost commented May 24, 2015

second question:

why can the plugin not be found here :


it('composes server with an manifest', function (done) {

        var manifest = {
            connections: [
                {
                    port: 3000,
                },
         ],
            plugins: {
                authentication: {
                    version: false,
                    plugins: 'lib'
        },
            version: [
                {
                    version: false,
                    plugins: 'lib'
                }
                    ]
            }
         };

        Glue.compose(manifest, function (err, server) {

            expect(err).to.not.exist();
            expect(server.connections).length(1);
            done();
        });
});

@ghost
Copy link

ghost commented May 24, 2015

I try to test if a server is started.

@ghost
Copy link

ghost commented May 24, 2015

How do I start the server. Do I need to add the whole part after starting the server to start.js ?

@ghost
Copy link

ghost commented May 24, 2015

no due date ??

@FennNaten
Copy link
Contributor

@roelof1967 For the test examples, you'd better go to a repo utilizing glue rather than the Glue repo itself. See e.g. aqua

In the plugins object of the manifest, each key should be the name of the target module if it's a npm module, or the relative path to it if the module is internal to the app. That's how Glue requires them before calling register.
e.g.

var manifest = {
    connections: [
        {
            port: 5000
        }
    ],
    plugins: {
        "./version": {} //the actual key depends on where you put your plugin and which folder you decide to use as relative root. Relative root is given as an option to the compose function.
    }
}

To be able to start the server and aim for minimal refactoring, you can keep a structure very similar to what we already have, e.g. just changing the init function in index.js to take manifest and glueOptions as params, replacing the server.register part by glue.compose, then changing start.js to pass in a manifest instead of a port.

@ghost
Copy link

ghost commented May 24, 2015

oke, so I schould not use the whole export.compose thing of the example which were pointed for a example manifest ?

@FennNaten
Copy link
Contributor

The example pointed at was more for the format of the manifest. The export.compose is the actual compose function you use from Glue (and you'll have to use it). You can check at the index.js and server.js from aqua for something closer to what we aim for.

@ghost
Copy link

ghost commented May 24, 2015

oke, I have now this : https://github.com/roelof1967/university and still not working :(

@FennNaten
Copy link
Contributor

@roelof1967 I made a quick example with server starting via npm start and plugin functionality kept (tests not updated yet). You may check lib/index.js and lib/start.js on this branch https://github.com/FennNaten/hueniversity/tree/assignment/glue-and-html-views if you're stuck.

@ghost
Copy link

ghost commented May 24, 2015

@FennNaten thanks, now the next problem. Making the test green

@zoe-1
Copy link
Contributor Author

zoe-1 commented May 24, 2015

@FennNaten Thank you for putting up the example :-)

@ghost
Copy link

ghost commented May 24, 2015

I have this test :


var Hapi = require('hapi');
var Code = require('code');
var Lab = require('lab');
var Composer = require('../lib/start');

// Test shortcuts

var lab = exports.lab = Lab.script();
var expect = Code.expect;
var it = lab.test;

it('starts server and returns hapi server object', function (done) {

    Composer(function (err, composedServer) {

        Code.expect(composedServer).to.be.an.object();
        done(err);
    });

}); 

But now I see this error message : function is not a object.

What went wrong this time ?

Roelof

@ghost
Copy link

ghost commented May 24, 2015

and when I do this :


plugins: {
        './version': {},
        './private': {},
        './home': {},

    }

I get a message that private is already registered. There is something wrong with the home but I do not see it.

@hueniverse
Copy link

@roelof1967 it would probably be better for everyone if you keep the discussion about your own submission within your pull request. This is a lot of noise here which makes it hard for people to participate and keep track of what is going on. Also, a lot of this would be better done in the gitter room for this repo.

@ghost
Copy link

ghost commented May 29, 2015

oke, I will do it that way

zoe-1 added a commit that referenced this issue May 31, 2015
@rutaihwa rutaihwa mentioned this issue Jun 3, 2015
zoe-1 added a commit to zoe-1/glue that referenced this issue Jun 21, 2015
* Summarized communication with @FennNaten from:
    * Assignment5 outmoded/university#136
    * and his PR outmoded/university#137

* Plus, added clarifiction made in gitter by @nlf
apoorvakorde added a commit to apoorvakorde/hapi-university that referenced this issue Feb 22, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.