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
// 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'; | |
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
'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 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
// 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 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
'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
const sync = require('fh-mbaas-api').sync | |
const workorders = require('lib/sql/workorders') | |
// Typical init code etc... | |
// Example of getting work orders for a specific user | |
sync.handleList('workorders', function(datasetId, query, metadata, done) { | |
// Getting by the userId passed to the sync framework and the region they are in | |
workorders.getDataForUserInRegion(query.userId, query.region, (err, specificUserWorkOrders) => { | |
if (err) { |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> | |
<title>Hello World</title> | |
<link rel="stylesheet" href="css/app.css"> | |
</head> | |
<body> |