This file contains hidden or 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' | |
// Ensure you run "npm install env-var@3 --save" | |
const env = require('env-var') | |
// Used to bypass check when running locally | |
const isLocal = env.get('FH_USE_LOCAL_DB').asBool() | |
// Valid mbaas IP(s) that can be in the "x-forwarded-for" header | |
// This must be set or app will not start (required() call) and must be comma separated |
This file contains hidden or 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 express = require('express') | |
const cors = require('cors') | |
const app = express() | |
// Enable CORS for all requests | |
app.use(cors()) |
This file contains hidden or 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
// Set a DEBUG environment var to "*" or "socket-logger" to enable | |
const log = require('debug')('socket-logger') | |
// Place this before other middlewares so it is invoked first - remember they invoke in the defined order | |
app.use(function (req, res, next) { | |
log('============================================================') | |
log(`received request from remote socket with req.headers - ${JSON.stringify(req.headers)}`) | |
log(`received request from remote socket with req.socket.address - ${JSON.stringify(req.socket.address())}`) | |
log(`received request from remote socket with req.socket.localAddress - ${req.socket.localAddress}`) |
This file contains hidden or 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 mongo = require('rhmap-mongodb'); | |
// First remove anything that might be in the collection | |
mongo.collection('test').remove({}) | |
.then(() => { | |
const start = Date.now(); | |
return doTest(1000) |
This file contains hidden or 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 mongo = require('rhmap-mongodb'); | |
// First remove anything that might be in the collection | |
mongo.collection('test').remove({}) | |
.then(doTest); | |
function doTest () { |
This file contains hidden or 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 Promise = require('bluebird'); | |
const fhc = Promise.promisifyAll(require('fh-fhc')); | |
const env = require('env-var'); | |
const log = require('fh-bunyan').getLogger(__filename); | |
const R = require('ramda'); | |
// fhc login and target vars. you can set these in bash using a command such as | |
// "export [email protected]", or by uncommenting the defaults below and |
This file contains hidden or 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
// Assume our api does not want these fields returned (ideally we would strip from db query, but you get the idea) | |
var cleanseData = R.map(R.omit('dob', 'social-security', 'nickname', 'height', 'favourite-movie')); | |
const age = 25; | |
// Remove users below an age | |
var filterData = R.filter((u) => { return u.age >= age }); | |
function getUsersOlderThanAge (age) { | |
// We could add a catch here if we want to add more error data... |
This file contains hidden or 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'; | |
var Promise = require('bluebird') | |
, express = require('express'); | |
var app = express(); | |
function getUsers () { | |
return new Promise(function (resolve, reject) { | |
resolve(['jane', 'john']); |
This file contains hidden or 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
Every second run is using async await, i.e 1 & 3 uses the callback server, and 2 & 4 use async await. | |
eshortis@eshortis-OSX:~/workspaces/personal/aysnc-await$ ab -n 10000 -c 250 -r http://127.0.0.1:3001/ | |
This is ApacheBench, Version 2.3 <$Revision: 1663405 $> | |
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ | |
Licensed to The Apache Software Foundation, http://www.apache.org/ | |
Benchmarking 127.0.0.1 (be patient) | |
Completed 1000 requests |
This file contains hidden or 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'; | |
var express = require('express') | |
, async = require('async'); | |
var app = express(); | |
function getAges (callback) { | |
callback(null, ['23', '43']); | |
} |