Skip to content

Instantly share code, notes, and snippets.

@devinivy
devinivy / hapi-mock-scheme.js
Created October 6, 2015 15:34
A mock auth scheme for testing
// Mock scheme for testing
server.auth.scheme('mock', function(server, options) {
return {
authenticate: function(request, reply) {
reply({credentials: options});
}
};
});
@devinivy
devinivy / deploy.sh
Last active May 25, 2021 14:44
Publish a hapi pal flavor
#!/usr/bin/env bash
branch=$(git symbolic-ref --short HEAD)
version=$1
if ! [[ $branch =~ ^flavor- ]]; then
echo "Not on a flavor branch" >&2
exit 1
fi
@devinivy
devinivy / stubQueryMethod.js
Last active September 29, 2020 10:31 — forked from wxactly/stubQueryMethod.js
Sails.js: Stub Waterline query method with Sinon.js
var util = require('util');
var _ = require('lodash');
var sinon = require('sinon');
/**
* Replaces a query method on the given model object with a stub. The query
* will still operate on a callback, and allow full access to waterline's
* deferred object. However, the query will not cause any I/O and instead
* will immediately resolve to the given result.
*
@devinivy
devinivy / deep-hapi-routes.js
Last active March 2, 2018 14:05
recursive require-dir for hapi routes
'use strict';
const tree = require('require-dir')(null, {
recurse: true // Consider also adding filter() to ignore e.g. helper directories
});
const flatten = (routes, obj) => {
if (Array.isArray(obj) || (obj.path && obj.method)) {
return routes.concat(obj);
@devinivy
devinivy / app.conf
Created July 14, 2016 13:06
Nginx reverse-proxy config for many apps
include /etc/nginx/conf.d/real-scheme.block;
upstream <app> {
server 127.0.0.1:<port>;
keepalive 16;
}
server {
listen 80;
server_name <server>;
@devinivy
devinivy / index.js
Created November 22, 2016 20:59
Underdog with vision
'use strict';
const Hapi = require('hapi');
const Underdog = require('underdog');
const Vision = require('vision');
const Handlebars = require('handlebars');
const Spdy = require('spdy');
const Http2 = require('http2');
const agent = new Http2.Agent({ rejectUnauthorized: false });
{"web-app": {
"servlet": [
{
"servlet-name": "cofaxCDS",
"servlet-class": "org.cofax.cds.CDSServlet",
"init-param": {
"configGlossary:installationAt": "Philadelphia, PA",
"configGlossary:adminEmail": "ksm@pobox.com",
"configGlossary:poweredBy": "Cofax",
"configGlossary:poweredByIcon": "/images/cofax.gif",
@devinivy
devinivy / push-me.js
Last active August 27, 2016 19:12
hapi with HTTP/2 server push
document.write('i was pushed!');
@devinivy
devinivy / sam-redux.md
Last active June 29, 2016 11:41
SAM meets Redux
  • model is a redux store.
  • actions are thunks.
  • nap() via model.subscribe().
  • present() is model.dispatch().
  • acceptor logic is redux middleware.
  • state/learner is implemented with ReactRedux.connect() and selectors (i.e. reselect).
@devinivy
devinivy / test-npmignore.sh
Created June 13, 2016 13:28
List the files that .npmignore will pack-up
# from https://github.com/hapijs/contrib/issues/90#issuecomment-224889568
tar -tf $(npm pack) && rm *.tgz