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
'use strict'; | |
const Joi = require('joi'); // object schema validation tool | |
const optionsSchema = Joi.object().keys({ | |
// a string representing a hostname or an ip | |
host: Joi.alternatives().try(Joi.string().hostname(), Joi.string().ip()).default('127.0.0.1'), | |
// a number in the allowed TCP port range, default to default mongodb port | |
port: Joi.number().min(1).max(65535).default(27017), | |
// If no database name, we create an random one that look like 'database_abcd' with a,b,c,d random numbers | |
database: Joi.string().min(1).replace(' ', '_').default(`database_${Math.floor(Math.random() * 10000)}`), |
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
/** | |
* Transforms an object to an array (drop the Object's keys) | |
* ``` | |
* let x = { a: 1, b: 2}; | |
* x.mapToArray() is [1, 2]; | |
* ``` | |
* @returns {Array} | |
*/ | |
Object.prototype.mapToArray = function () { |
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
'use strict'; | |
const Mongoose = require('mongoose'); | |
const Schema = Mongoose.Schema; | |
const userSchema = new Schema({ | |
githubid: { | |
type: String, | |
required: true, | |
select: 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
'use strict'; | |
const User = require('../models/user.model'); | |
const Boom = require('boom'); | |
/** | |
* save anew user if no conflict occurs | |
* @param candidateUser | |
* @returns {Promise.<*>} | |
*/ | |
module.exports.save = function (candidateUser) { |
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
'use strict'; | |
const AuthService = require('../services/auth.service'); | |
// { method: ['GET', 'POST'], path: '/login', config: AuthController.login } | |
module.exports.login = { | |
description: 'Sign-in a user in the app', | |
tags: ['auth'], | |
auth: 'github', | |
handler: function (request, reply) { |
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
'use strict'; | |
const AuthController = require('./api/auth'); | |
const UserController = require('./api/user'); | |
module.exports.routes = [ | |
// auth | |
{ method: ['GET', 'POST'], path: '/login', config: AuthController.login }, | |
{ method: 'GET', path: '/logout', config: AuthController.logout }, |
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
'use strict'; | |
const Bell = require('bell'); | |
const AuthBearer = require('hapi-auth-bearer-token'); | |
const AuthService = require('./lib/services/auth.service'); | |
const Routes = require('./lib').routes; | |
exports.register = function (server, options, next) { | |
if (!options.github){ |
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
'use strict'; | |
const Module = require('module'); | |
const originalCompile = Module.prototype._compile; | |
const nohook = function (content, filename, done) { | |
return done(content); | |
}; | |
let currentHook = nohook; |
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
'use strict'; | |
const Hook = require('compile-hook'); | |
const Acorn = require('acorn-jsx'); | |
const Falafel = require('falafel'); | |
const hijack = function (script) { | |
return Falafel(script, { parser: Acorn }, function (node) { | |
if (node.type === 'AssignmentExpression' && node.source().includes('module.exports')) { |
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
'use strict'; | |
require('@vdeturckheim/exploic'); | |
const jwt = require('jsonwebtoken'); | |
const token = jwt.sign({ foo: 'bar'}, 'shhhhh'); | |
console.log(token); |