Skip to content

Commit 30bf5ab

Browse files
Changed the module into a HAPI plugin
1 parent f925845 commit 30bf5ab

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

index.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
module.exports = {
2-
server: require('./lib/server'),
3-
serializers: require('./lib/serializers'),
4-
decorator: require('./lib/decorator')
1+
var pkg = require('./package.json'),
2+
server = require('./lib/server');
3+
4+
module.exports = function (orm) {
5+
var register = function register (plugin, options, next) {
6+
// Setup the server
7+
server(orm, plugin);
8+
9+
next();
10+
};
11+
12+
// Add the attributes to the plugin
13+
register.attributes = {pkg: pkg}
14+
15+
// Return the plugin
16+
return register;
517
};

lib/server/index.js

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
var Hapi = require('hapi'),
2-
Intaglio = require('intaglio');
1+
var Intaglio = require('intaglio'),
2+
serializer = require('../serializers/hal');
33

4-
module.exports = function (orm, host, port, serializer, options) {
4+
module.exports = function (orm, plugin) {
55
Intaglio.utils.assert('`orm` is required!', orm !== undefined);
6-
Intaglio.utils.assert('`host` is required!', host !== undefined);
7-
Intaglio.utils.assert('`port` is required!', port !== undefined);
8-
Intaglio.utils.assert('`serializer` is required!', serializer !== undefined);
6+
Intaglio.utils.assert('`plugin` is required!', plugin !== undefined);
97

10-
var server = Hapi.createServer(host, port, options),
11-
routes = [
8+
var routes = [
129
{
1310
path: '/api/{model}/{id?}',
1411
method: 'GET',
@@ -71,7 +68,7 @@ module.exports = function (orm, host, port, serializer, options) {
7168
}
7269
];
7370

74-
server.route(routes);
71+
plugin.route(routes);
7572

76-
return server;
73+
return plugin;
7774
};

0 commit comments

Comments
 (0)