-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added base level routing and generic auth
- Loading branch information
Showing
208 changed files
with
13,301 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"asi": false, | ||
"bitwise": false, | ||
"boss": true, | ||
"browser": true, | ||
"curly": true, | ||
"debug": false, | ||
"devel": false, | ||
"eqeqeq": true, | ||
"eqnull": false, | ||
"esversion": 6, | ||
"evil": false, | ||
"expr": false, | ||
"forin": false, | ||
"globalstrict": false, | ||
"globals": { | ||
"angular": true | ||
}, | ||
"immed": true, | ||
"latedef": "nofunc", | ||
"laxbreak": true, | ||
"loopfunc": false, | ||
"maxerr": 100, | ||
"newcap": true, | ||
"noarg": true, | ||
"node": true, | ||
"noempty": true, | ||
"nomen": true, | ||
"nonew": true, | ||
"onevar": false, | ||
"passfail": false, | ||
"plusplus": false, | ||
"predef": [], | ||
"quotmark": "single", | ||
"regexdash": false, | ||
"regexp": false, | ||
"scripturl": true, | ||
"shadow": true, | ||
"strict": true, | ||
"sub": true, | ||
"supernew": true, | ||
"trailing": true, | ||
"undef": true, | ||
"unused": true, | ||
"white": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var imageConfig = { | ||
'userIcon': { | ||
'sizes': [100, 300] | ||
} | ||
}; | ||
|
||
exports.default = imageConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
'use strict'; | ||
|
||
var _hapi = require('hapi'); | ||
|
||
var _hapi2 = _interopRequireDefault(_hapi); | ||
|
||
var _cluster = require('cluster'); | ||
|
||
var _cluster2 = _interopRequireDefault(_cluster); | ||
|
||
var _os = require('os'); | ||
|
||
var _os2 = _interopRequireDefault(_os); | ||
|
||
var _inert = require('inert'); | ||
|
||
var _inert2 = _interopRequireDefault(_inert); | ||
|
||
var _vision = require('vision'); | ||
|
||
var _vision2 = _interopRequireDefault(_vision); | ||
|
||
var _hapiSwagger = require('hapi-swagger'); | ||
|
||
var _hapiSwagger2 = _interopRequireDefault(_hapiSwagger); | ||
|
||
var _hapiAuthJwt = require('hapi-auth-jwt2'); | ||
|
||
var _hapiAuthJwt2 = _interopRequireDefault(_hapiAuthJwt); | ||
|
||
var _models = require('./models'); | ||
|
||
var _models2 = _interopRequireDefault(_models); | ||
|
||
var _envVariables = require('../envVariables'); | ||
|
||
var _envVariables2 = _interopRequireDefault(_envVariables); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
require('babel-core/register'); | ||
|
||
// Create Server | ||
var server = new _hapi2.default.Server(); | ||
server.connection({ | ||
port: _envVariables2.default.apiPort | ||
}); | ||
|
||
var options = { | ||
'info': { | ||
'title': 'Sandbox 3 API Documentation', | ||
'version': _envVariables2.default.version | ||
}, | ||
'basePath': '/api/', | ||
'pathPrefixSize': 2 | ||
}; | ||
|
||
var validateUser = function validateUser(decodedToken, request, callback) { | ||
// Investigate ways to improve validation and allow access based on specific request and related user details | ||
var error = void 0; | ||
var credentials = { | ||
'id': decodedToken.id, | ||
'username': decodedToken.username, | ||
'scope': decodedToken.scope | ||
}; | ||
|
||
return callback(error, true, credentials); | ||
}; | ||
|
||
// Register Swagger Plugin ( Use for documentation and testing purpose ) | ||
server.register([_inert2.default, _vision2.default, { | ||
'register': _hapiSwagger2.default, | ||
'options': options | ||
}], { | ||
'routes': { | ||
'prefix': '/api' | ||
} | ||
}, function (err) { | ||
if (err) { | ||
server.log(['error'], 'hapi-swagger load error: ' + err); | ||
} else { | ||
server.log(['start'], 'hapi-swagger interface loaded'); | ||
} | ||
}); | ||
|
||
// Register hapi-auth-jwt2 Plugin | ||
server.register(_hapiAuthJwt2.default, function (err) { | ||
if (err) { | ||
console.log(err); | ||
return; | ||
} | ||
server.auth.strategy('jsonWebToken', 'jwt', { | ||
'key': _envVariables2.default.secret, | ||
'verifyOptions': { | ||
'algorithms': ['HS256'] | ||
}, | ||
'validateFunc': validateUser | ||
}); | ||
|
||
// Routes | ||
server.route(require('./routes')); | ||
}); | ||
|
||
// Cluster config and server start | ||
if (false /* cluster.isMaster */) { | ||
var numWorkers = _os2.default.cpus().length; | ||
|
||
console.log('Master cluster setting up ' + numWorkers + ' workers...'); | ||
|
||
for (var i = 0; i < numWorkers; i++) { | ||
_cluster2.default.fork(); | ||
} | ||
|
||
_cluster2.default.on('online', function (worker) { | ||
console.log('Worker ' + worker.process.pid + ' is online'); | ||
}); | ||
|
||
_cluster2.default.on('exit', function (worker, code, signal) { | ||
console.log('Worker ' + worker.process.pid + ' died with code: ' + code + ', and signal: ' + signal); | ||
console.log('Starting a new worker'); | ||
_cluster2.default.fork(); | ||
}); | ||
} else { | ||
_models2.default.sequelize.sync().then(function () { | ||
server.start(function (err) { | ||
if (err) { | ||
throw err; | ||
} | ||
console.log('Server running at:', server.info.uri, 'with process id', process.pid); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
module.exports = function (sequelize, DataTypes) { | ||
var Contact = sequelize.define('Contact', { | ||
'firstName': DataTypes.STRING, | ||
'lastName': DataTypes.STRING, | ||
'middleName': DataTypes.STRING, | ||
'email': DataTypes.STRING, | ||
'gender': DataTypes.STRING, | ||
'mobilePhone': DataTypes.STRING, | ||
'fax': DataTypes.STRING, | ||
'type': { | ||
'type': DataTypes.STRING, | ||
'defaultValue': 'contact' | ||
}, | ||
'status': { | ||
'type': DataTypes.BOOLEAN, | ||
'defaultValue': true | ||
}, | ||
'maritalStatus': { | ||
'type': DataTypes.STRING, | ||
'defaultValue': 'married' | ||
} | ||
}, { | ||
'classMethods': { | ||
'associate': function associate(models) { | ||
Contact.hasMany(models.File); | ||
Contact.belongsTo(models.Provider); | ||
} | ||
} | ||
}); | ||
return Contact; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
module.exports = function (sequelize, DataTypes) { | ||
var File = sequelize.define('File', { | ||
'name': DataTypes.STRING, | ||
'size': DataTypes.INTEGER, | ||
'type': DataTypes.STRING | ||
}, { | ||
'classMethods': { | ||
'associate': function associate(models) { | ||
File.belongsTo(models.Contact); | ||
} | ||
} | ||
}); | ||
return File; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
|
||
var _fs = require('fs'); | ||
|
||
var _fs2 = _interopRequireDefault(_fs); | ||
|
||
var _path = require('path'); | ||
|
||
var _path2 = _interopRequireDefault(_path); | ||
|
||
var _sequelize = require('sequelize'); | ||
|
||
var _sequelize2 = _interopRequireDefault(_sequelize); | ||
|
||
var _databaseConfig = require('../databaseConfig'); | ||
|
||
var _databaseConfig2 = _interopRequireDefault(_databaseConfig); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
var basename = _path2.default.basename(module.filename); | ||
var env = process.env.NODE_ENV || 'development'; | ||
var config = _databaseConfig2.default[env]; | ||
var db = {}; | ||
|
||
if (config.use_env_variable) { | ||
var sequelize = new _sequelize2.default(process.env[config.use_env_variable]); | ||
} else { | ||
var sequelize = new _sequelize2.default(config.database, config.username, config.password, config); | ||
} | ||
|
||
_fs2.default.readdirSync(__dirname).filter(function (file) { | ||
return file.indexOf('.') !== 0 && file !== basename && file.slice(-3) === '.js'; | ||
}).forEach(function (file) { | ||
var model = sequelize['import'](_path2.default.join(__dirname, file)); | ||
db[model.name] = model; | ||
}); | ||
|
||
Object.keys(db).forEach(function (modelName) { | ||
if (db[modelName].associate) { | ||
db[modelName].associate(db); | ||
} | ||
}); | ||
|
||
db.sequelize = sequelize; | ||
db.Sequelize = _sequelize2.default; | ||
|
||
module.exports = db; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
module.exports = function (sequelize, DataTypes) { | ||
var Provider = sequelize.define('Provider', { | ||
'name': DataTypes.STRING, | ||
'dba': DataTypes.STRING, | ||
'email': DataTypes.STRING, | ||
'identifier': DataTypes.STRING, | ||
'identifierType': DataTypes.STRING, | ||
'legalName': DataTypes.STRING, | ||
'phone': DataTypes.STRING, | ||
'providerNumber': DataTypes.STRING, | ||
'state': { | ||
'type': DataTypes.STRING, | ||
'defaultValue': 'active' | ||
} | ||
}, { | ||
'classMethods': { | ||
'associate': function associate(models) { | ||
Provider.hasMany(models.Contact); | ||
} | ||
} | ||
}); | ||
return Provider; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
module.exports = function (sequelize, DataTypes) { | ||
var User = sequelize.define('User', { | ||
'email': { | ||
'type': DataTypes.STRING, | ||
'unique': true | ||
}, | ||
'username': { | ||
'type': DataTypes.STRING, | ||
'unique': true | ||
}, | ||
'password': DataTypes.STRING, | ||
'firstName': DataTypes.STRING, | ||
'lastName': DataTypes.STRING, | ||
'siteAdmin': { | ||
'type': DataTypes.BOOLEAN, | ||
'defaultValue': false | ||
}, | ||
'providerAdmin': { | ||
'type': DataTypes.BOOLEAN, | ||
'defaultValue': false | ||
}, | ||
'contactAdmin': { | ||
'type': DataTypes.BOOLEAN, | ||
'defaultValue': false | ||
} | ||
}, { | ||
'classMethods': {} | ||
}); | ||
return User; | ||
}; |
Oops, something went wrong.