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

[Assignment 2]Convert to a plugin #69

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,21 @@

var Hapi = require('hapi');
var Hoek = require('hoek');
var Package = require('../package.json');

var Vertsion = require('./version');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo


// Declare internals

var internals = {};


internals.init = function () {

var server = new Hapi.Server();
server.connection({ port: 8000 });

server.route({
method: 'GET',
path: '/version',
config: {
description: 'Returns the version of the server',
handler: function (request, reply) {

return reply({ version: Package.version });
}
server.register({
register: Vertsion
}, function(err) {
if (err) {
console.error('Failed to load plugin:', err);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the same error validation here as in server.start() also see #43 for general feedback that could help you!

}
});

Expand Down
23 changes: 23 additions & 0 deletions lib/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

var Package = require('../package.json');

//Plugin
exports.register = function (server, options, next) {
server.route({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline after function

method: 'GET',
path: '/version',
config: {
description: 'Returns the version of the server',
handler: function (request, reply) {
return reply({ version: Package.version });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline after function

}
}
});
next();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline + return next() for readability

};

//Attributes
exports.register.attributes = {
pkg: Package
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the attribute of this plugin are not the same as that of the server!

};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline at end of file