Skip to content

Commit

Permalink
[assignment 2] Convert version route to plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Myles Borins committed Mar 18, 2015
1 parent a5ebe79 commit f1231e7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
19 changes: 4 additions & 15 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,20 @@

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


// 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(internals.version, function (err) {

Hoek.assert(!err, err);
});

server.start(function (err) {

Hoek.assert(!err, err);
Expand Down
27 changes: 27 additions & 0 deletions lib/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Declare internals
var internals = {
response: {
version: require('../package.json').version
}
};

// Register plugin
exports.register = function (server, options, next) {
server.route({
method: 'GET',
path: '/version',
config: {
description: 'Returns the version of the server',
handler: function (request, reply) {

return reply(internals.response);
}
}
});
next();
};

// Plugin metadata
exports.register.attributes = {
name: 'version'
};

0 comments on commit f1231e7

Please sign in to comment.