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 #179

Merged
merged 5 commits into from
Jan 19, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ config.json
*/._*
*/*/._*
coverage.*
.settings
33 changes: 13 additions & 20 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
};

Expand Down
35 changes: 35 additions & 0 deletions lib/version.js
Original file line number Diff line number Diff line change
@@ -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'
}
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}