Skip to content

Commit

Permalink
eslinted no errors or warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
glennjones committed Dec 5, 2015
1 parent 5820d63 commit fa17e18
Show file tree
Hide file tree
Showing 32 changed files with 5,579 additions and 5,585 deletions.
624 changes: 297 additions & 327 deletions bin/routes.js

Large diffs are not rendered by default.

147 changes: 78 additions & 69 deletions bin/test-server.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,70 @@
var Hapi = require('hapi'),
Inert = require('inert'),
Vision = require('vision'),
Blipp = require('blipp'),
H2o2 = require('h2o2'),
BearerToken = require('hapi-auth-bearer-token'),
HapiSwagger = require('../'),
Pack = require('../package'),
Routes = require('./routes');
'use strict';

var BearerToken = require('hapi-auth-bearer-token'),
Blipp = require('blipp'),
H2o2 = require('h2o2'),
Hapi = require('hapi'),
Inert = require('inert'),
Vision = require('vision');

var HapiSwagger = require('../'),
Pack = require('../package'),
Routes = require('./routes');


var server = new Hapi.Server();
server.connection({
host: 'localhost',
port: 3000
});
server.connection({
host: 'localhost',
port: 3000
});

var swaggerOptions = {
info: {
'title': 'Test API Documentation',
'description': 'This is a sample example of API documentation.',
'version': Pack.version,
'termsOfService': 'https://github.com/glennjones/hapi-swagger/',
'contact': {
'email': '[email protected]'
},
'license': {
'name': 'MIT',
'url': 'https://raw.githubusercontent.com/glennjones/hapi-swagger/master/license.txt'
}
info: {
'title': 'Test API Documentation',
'description': 'This is a sample example of API documentation.',
'version': Pack.version,
'termsOfService': 'https://github.com/glennjones/hapi-swagger/',
'contact': {
'email': '[email protected]'
},
tags: [{
'name': 'store',
'description': 'Storing a sum',
'externalDocs': {
'description': 'Find out more',
'url': 'http://example.org'
}
},{
'name': 'sum',
'description': 'API of sums',
'externalDocs': {
'description': 'Find out more',
'url': 'http://example.org'
'license': {
'name': 'MIT',
'url': 'https://raw.githubusercontent.com/glennjones/hapi-swagger/master/license.txt'
}
},
tags: [{
'name': 'store',
'description': 'Storing a sum',
'externalDocs': {
'description': 'Find out more',
'url': 'http://example.org'
}
}, {
'name': 'sum',
'description': 'API of sums',
'externalDocs': {
'description': 'Find out more',
'url': 'http://example.org'
}
}],
securityDefinitions: {
'petstore_auth': {
'type': 'oauth2',
'authorizationUrl': 'http://petstore.swagger.io/api/oauth/dialog',
'flow': 'implicit',
'scopes': {
'write:pets': 'modify pets in your account',
'read:pets': 'read your pets'
}
}],
securityDefinitions: {
'petstore_auth': {
'type': 'oauth2',
'authorizationUrl': 'http://petstore.swagger.io/api/oauth/dialog',
'flow': 'implicit',
'scopes': {
'write:pets': 'modify pets in your account',
'read:pets': 'read your pets'
}
},
'api_key': {
'type': 'apiKey',
'name': 'api_key',
'in': 'header'
}
},
security: [{'api_key': []}]
};


},
'api_key': {
'type': 'apiKey',
'name': 'api_key',
'in': 'header'
}
},
security: [{ 'api_key': [] }]
};


server.register([
Expand All @@ -75,32 +77,39 @@ server.register([
register: HapiSwagger,
options: swaggerOptions
}], function (err) {

server.auth.strategy('bearer', 'bearer-access-token', {
'accessTokenName': 'access_token',
'validateFunc': validateBearer
});
server.start(function(){
server.start(function () {

console.log('server running at:', server.info.uri);
});
});

server.route(Routes);


// validation function for bearer strategy
function validateBearer(token, callback) {
if(token === '12345'){
/**
* validation function for bearer strategy
*
* @param {Object} token
* @param {Function} callback
*/
var validateBearer = function (token, callback) {

if (token === '12345') {
callback(null, true, {
token: token,
user: {
username: 'glennjones',
name: 'Glenn Jones',
groups: ['admin','user']
groups: ['admin', 'user']
}
});
}else{
} else {
// for bad token keep err as null
callback(null, false, {});
callback(null, false, {});
}
}

};
Loading

0 comments on commit fa17e18

Please sign in to comment.