Skip to content

Commit

Permalink
Merge pull request #3 from devinivy/hapi8
Browse files Browse the repository at this point in the history
Upgrade to hapi8, lint for hapi style.
  • Loading branch information
devinivy committed Aug 10, 2015
2 parents c1f8e12 + 629aaa2 commit 0c83bf0
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 111 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.tmp
15 changes: 7 additions & 8 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
var Path = require('path');

module.exports = {

product: {
name: 'boilerplate-api'
},

server: {
boilerplateApi: {
host: 'localhost',
port: 3004 // choose a new one
host: '0.0.0.0',
port: process.env.PORT || 3000
}
},

dogwater: {
connections: {
diskDb: {
Expand All @@ -28,10 +28,9 @@ module.exports = {
pattern: 'fixtures.js'
}
},

poop: {
logPath: Path.join(__dirname, 'poop.log')
}

}

};
1 change: 0 additions & 1 deletion index.js

This file was deleted.

126 changes: 66 additions & 60 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,75 @@ var Path = require('path');
var Hoek = require('hoek');
var Joi = require('joi');
var Config = require('../config');
var Package = require('../package.json');

exports.register = function(plugin, options, next) {

plugin.dependency('dogwater', function(plugin, _next) {

plugin.register([

{
plugin: require('hapi-swagger'),
options: {
basePath: Config.server.boilerplateApi.uri,
apiVersion: 1,
enableDocumentationPage: false
}
},
{
plugin: require('bedwetter'),
// TODO: Set this up, especially user model, etc.
options: {
actAsUser: true,
userIdProperty: 'user.id',
setOwner: false,
requireOwner: false,
userUrlPrefix: '/user',
userModel: 'users',
ownerAttr: 'owner',
childOwnerAttr: 'owner'
}
},
{
plugin: require('bassmaster'),
options: {
batchEndpoint: '/',
tags: ['bassmaster']
}
exports.register = function (server, options, next) {

server.register([
{
// Tag routes with "api" for use with swagger.
register: require('hapi-swagger'),
options: {
basePath: Config.server.boilerplateApi.uri,
apiVersion: 1,
enableDocumentationPage: false
}
},
{
register: require('bedwetter'),
options: {
actAsUser: true,
userIdProperty: 'user.id',
setOwner: false,
requireOwner: false,
userUrlPrefix: '/user',
userModel: 'users',
ownerAttr: 'owner',
childOwnerAttr: 'owner'
}
},
{
register: require('bassmaster'),
options: {
batchEndpoint: '/',
tags: ['bassmaster']
}
],
function(err) {
if (err) return _next(err);

// TODO: bedwetter, etc. routes go here or outside the dogwater dependency block altogether.
plugin.route([
// Swagger docs
{
method: 'GET',
path: '/swagger',
handler: {file: Path.normalize(__dirname + '/swagger.html')}
}
],
function (err) {

if (err) {
return next(err);
}

// Pinger
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {

reply({ ping: 'pong', version: Package.version });
}

]);

return _next();

});


// Swagger docs
server.route({
method: 'GET',
path: '/swagger',
handler: { file: Path.normalize(__dirname + '/swagger.html') }
});

/**
* For example...
* server.route(require('./routes/dogs')(server, options));
*/

next();
});

next();

}

exports.register.attributes = require('../package.json');
};

exports.register.attributes = {
pkg: Package,
dependencies: 'dogwater'
};
14 changes: 7 additions & 7 deletions lib/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ module.exports = [];
var modelObject;

Fs.readdirSync(__dirname).forEach(function (file) {

/* If it's the current file ignore it */
if (file === 'index.js') return;

if (file === 'index.js') {
return;
}

/* Grab a model definition */
modelObject = require(Path.join(__dirname, file));

/* Push to module.exports. Should export an array to work with dogwater. */
module.exports.push(modelObject);

});


});
Empty file added lib/routes/.gitkeep
Empty file.
29 changes: 15 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "boilerplate-api",
"version": "0.0.0",
"description": "Boilerplate's API",
"main": "index.js",
"description": "Boilerplate API",
"main": "lib/index.js",
"scripts": {
"start": "node server.js",
"test": "make test-cov"
"test": "lab -a code -L"
},
"repository": {
"type": "git",
Expand All @@ -18,18 +18,19 @@
},
"homepage": "https://github.com/devinivy/boilerplate-api",
"dependencies": {
"hapi": "~7.x.x",
"boom": "~2.6.x",
"poop": "~1.2.x",
"hoek": "~2.4.x",
"joi": "~4.7.x",
"bassmaster": "~1.6.x",
"bedwetter": "~1.x.x",
"dogwater": "~0.4.x",
"hapi-swagger": "~0.4.x",
"sails-disk": "git://github.com/devinivy/sails-disk.git#master"
"hapi": "8.x.x",
"glue": "2.x.x",
"boom": "2.8.x",
"poop": "1.2.x",
"hoek": "2.x.x",
"joi": "6.x.x",
"bassmaster": "1.8.x",
"bedwetter": "1.x.x",
"dogwater": "0.4.x",
"hapi-swagger": "0.8.x",
"sails-disk": "0.10.x"
},
"devDependencies": {
"lab": "4.x.x"
"lab": "5.x.x"
}
}
51 changes: 30 additions & 21 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,59 @@
var Path = require('path');
var Hapi = require('hapi');
var Glue = require('glue');
var Config = require('./config');


Config.server.boilerplateApi.uri = (Config.server.boilerplateApi.tls ? 'https://' : 'http://') + Config.server.boilerplateApi.host + ':' + Config.server.boilerplateApi.port;

Config.server.boilerplateApi.uri = (Config.server.boilerplateApi.tls ? 'https://' : 'http://') +
Config.server.boilerplateApi.host + ':' +
Config.server.boilerplateApi.port;

var manifest = {
pack: {

server: {
app: {
config: Config,
config: Config
}
},
servers: [

connections: [
{
host: Config.server.boilerplateApi.host,
port: Config.server.boilerplateApi.port,
options: {
labels: 'boilerplate-api',
labels: 'boilerplate-api',
routes: {
cors: true
}
},
}
],

plugins: {

// General porpoise
'./dogwater': Config.dogwater,
'./poop': Config.poop,

// Server-specific
'../lib': [{ select: 'boilerplate-api' }]

}

};

module.exports = manifest;

// If this is being required, return the manifest. Otherwise, start the pack.
// If this is being required, return the manifest. Otherwise, start the server.
if (!module.parent) {
Hapi.Pack.compose(manifest, { relativeTo: Path.join(__dirname, 'node_modules') }, function (err, pack) {

pack.start();
});
}
Glue.compose(manifest, { relativeTo: Path.join(__dirname, 'node_modules') }, function (err, server) {

if (err) {

throw err;
}

server.start(function () {

console.log('Started on ' + Config.server.boilerplateApi.uri);
});
});
}

0 comments on commit 0c83bf0

Please sign in to comment.