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
/** | |
* Proper (according to me) "isPresent" method for arrays in javascript. This allows the use of callback on testing. | |
* An empty callback is like using '==' as test. | |
* @param item item to find | |
* @param cpf -optional- test callback function: function(a,b) where a is the element to find and b the element tested | |
* from the array. | |
* @returns {boolean} true if at least one element is present in the array equals to the one to find according to the | |
* compare function. | |
* @author Vladimir de Turckheim | |
*/ |
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
{ | |
"name": "intro", | |
"version": "0.1.0", | |
"description": "Short introduction to Lab and Hapi", | |
"main": "index.js", | |
"scripts": { | |
"test": "lab -cLv -t 100", | |
"start": "node ./index" | |
}, |
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'; | |
// Hapi framework | |
const Hapi = require('hapi'); | |
// our plugin in the file api.js | |
const ApiPlugin = require('./api'); | |
// We create a server object | |
const server = new Hapi.Server(); | |
// Server will listen on port 8080 | |
server.connection({ |
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'; | |
// Hapi framework | |
const Hapi = require('hapi'); | |
// our plugin in the file api.js | |
const ApiPlugin = require('../api'); | |
// assertion library | |
const Code = require('code'); | |
// Lab test runner | |
const Lab = require('lab'); |
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
const Thinky = require('thinky')(); | |
const Type = Thinky.type; | |
// create the model for messages | |
const Message = Thinky.createModel('Message', { | |
username: Type.string(), | |
message: Type.string() | |
}); |
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
const Hapi = require('hapi'); | |
const Path = require('path'); | |
const server = new Hapi.Server(); | |
server.connection({ port: 4000 }); | |
server.register([require('inert'), require('susie')], err => { | |
if (err) { |
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
{ | |
config: { | |
validate: { | |
payload: { | |
message: Joi.string(), | |
username: Joi.string() | |
} | |
} | |
}, | |
method: 'POST', |
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
{ | |
method: 'GET', | |
path: '/chat-feed', | |
handler: function (request, reply) { | |
Message | |
.changes() | |
.run() | |
.then((feed) => { | |
feed.each((err, doc) => { |
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
var evtSource = new EventSource("/chat-feed"); | |
evtSource.addEventListener("message", e => { | |
// e.data == the message that has been received | |
}); |
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 validateOptions = require('./lib').validateOptions; | |
const builConnectionString = require('./lib').builConnectionString; | |
module.exports.register = function (server, options, next) { | |
const validation = validateOptions(options); |
OlderNewer