hapi-mongoose-request
v1.0.1
Published
Set models in every request for Hapi.js
Downloads
2
Maintainers
Readme
hapi-mongoose-request
Set models in every request for Hapi.js
Install
$ npm install hapi-mongoose-request
Usage
var Hapi = require('hapi');
var server = new Hapi.Server();
server.connection({ port: 8000 });
server.register([{
register: require('hapi-mongoose-connect'),
options: {
uri: 'mongodb://localhost/my-database'
}
}, {
register: require('hapi-mongoose-models'),
options: {
pattern: './models/**/*.js',
options: {
cwd: __dirname
}
}
}, {
register: require('hapi-mongoose-request'),
options: {
param: 'model', // Default 'model'
capitalize: true, // Capitalize all the incoming route parameter, default true
singularize: true // Singularize all the incoming route parameter, default true
}
}], function (err) {
if (err) {
throw err;
}
server.route({
method: 'GET',
path: '/api/v1/{model}', // The same is declared in the options
method: function (request, reply) {
if (request.Model) {
request.Model.find(function (err, docs) {
reply(err, docs);
});
}
else {
reply({ message: 'Not found' }).code(404);
}
}
});
server.start(function (err) {
if (err) {
throw err;
}
console.log('Server started at: ' + server.info.uri);
});
}
});
Tests
Run comand make test
or npm test
. Include 100% test coverage.
License
MIT