-
Notifications
You must be signed in to change notification settings - Fork 192
[Assignment 2]Convert to a plugin #69
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,28 +2,21 @@ | |
|
||
var Hapi = require('hapi'); | ||
var Hoek = require('hoek'); | ||
var Package = require('../package.json'); | ||
|
||
var Vertsion = require('./version'); | ||
|
||
// 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use the same error validation here as in |
||
} | ||
}); | ||
|
||
|
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({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. newline after function |
||
} | ||
} | ||
}); | ||
next(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. newline + |
||
}; | ||
|
||
//Attributes | ||
exports.register.attributes = { | ||
pkg: Package | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! |
||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo