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

Move route version into its own plugin. #61

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
17 changes: 5 additions & 12 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,22 @@

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


// Declare internals

var internals = {};
var internals = {
version: 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.

It is a module you should assign it to Version and then register it

};


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

return reply({ version: Package.version });
}
}
Hoek.assert(!err,err);
});

server.start(function (err) {
Copy link

Choose a reason for hiding this comment

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

you should start your server after the plugins have been registered. it needs to be placed in the server.register callback.

Expand Down
25 changes: 25 additions & 0 deletions lib/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var Package = require('../package');

var internals = {
response: {
version: Package.version
}
};

exports.register = function (server, options, next) {

server.route({
method: 'GET',
path: '/version',
handler: function(request, reply) {

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

return next();
};

exports.register.attributes = {
name: 'version'
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hueniversity",
"version": "0.0.1",
"version": "0.0.2",
"description": "Community learning experiment",
"main": "lib/index.js",
"repository": {
Expand Down