diff --git a/.gitignore b/.gitignore index 12db069..c67999d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ config.json */._* */*/._* coverage.* +.settings diff --git a/lib/index.js b/lib/index.js index c97a4c6..cfdffd4 100755 --- a/lib/index.js +++ b/lib/index.js @@ -1,36 +1,29 @@ +'use strict'; + // Load modules -var Hapi = require('hapi'); -var Hoek = require('hoek'); -var Package = require('../package.json'); +const Hapi = require('hapi'); +const Hoek = require('hoek'); +const Version = require('./version'); // Declare internals -var internals = {}; +const internals = {}; internals.init = function () { - var server = new Hapi.Server(); + const 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.start(function (err) { + server.register(Version, (err) => { Hoek.assert(!err, err); - console.log('Server started at: ' + server.info.uri); + server.start((err) => { + + Hoek.assert(!err, err); + console.log('Server started at: ' + server.info.uri); + }); }); }; diff --git a/lib/version.js b/lib/version.js new file mode 100644 index 0000000..19c5dc2 --- /dev/null +++ b/lib/version.js @@ -0,0 +1,35 @@ +'use strict'; + +// Load modules + +const Package = require('../package.json'); + + +// Declare internals + +const internals = { + response: { + version: Package.version + } +}; + +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); + } + } + }); + + return next(); +}; + +exports.register.attributes = { + name: 'version' +} diff --git a/package.json b/package.json index 3bf1561..30e054a 100644 --- a/package.json +++ b/package.json @@ -1,28 +1,27 @@ { - "name": "hueniversity", - "version": "0.0.1", + "name": "hapi-university", + "version": "0.0.2", "description": "Community learning experiment", "main": "lib/index.js", "repository": { "type": "git", - "url": "https://github.com/hueniverse/hueniversity.git" + "url": "https://github.com/hapijs/university.git" }, "keywords": [ "hapi", "learn", "community" ], - "license": "BSD", + "license": "BSD-3-Clause", "bugs": { - "url": "https://github.com/hueniverse/hueniversity/issues" + "url": "https://github.com/hapijs/university/issues" }, - "homepage": "https://github.com/hueniverse/hueniversity", + "homepage": "https://github.com/hapijs/university", "dependencies": { - "hapi": "8.x.x", - "hoek": "2.x.x" + "hapi": "12.x.x", + "hoek": "3.x.x" }, "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", "start": "node lib/index.js" } }