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
module['exports'] = function echoHttp (hook) { | |
var path = require('path'); | |
var SpellCheck = require('spellcheck'), | |
base = __dirname + "../../../../modules/builds/hunspell/en_US/"; | |
base = path.resolve(base); | |
base = base + "/"; | |
spell = new SpellCheck(base + 'en_US.aff', base + 'en_US.dic'); | |
// If the hook is not currently streaming, req has already been fully buffered |
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
module['exports'] = function geoipHook (hook) { | |
var geoip = require('geoip-lite'); | |
var ip = hook.params.ip; | |
if (typeof ip === "undefined" || ip.length === 0) { | |
ip = hook.req.headers['x-forwarded-for']; | |
} | |
console.log('attempting to lookup ' + ip); | |
var geo = geoip.lookup(ip); | |
if (geo === null) { | |
return hook.res.end(JSON.stringify({ message: "invalid ip " + ip.toString(), error: true }, true, 2)); |
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
module['exports'] = function markdownHook (hook) { | |
var marked = require('marked'); | |
// TODO: expose parser options through schema | |
marked.setOptions({ | |
renderer: new marked.Renderer(), | |
gfm: true, | |
tables: true, | |
breaks: false, | |
pedantic: false, | |
sanitize: true, |
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
module['exports'] = function getCoin (hook) { | |
var request = require('request'); | |
var url = 'http://coinmarketcap-nexuist.rhcloud.com/api/' + hook.params.coin; | |
request(url, { json: true }, function (err, response, body) { | |
if (hook.params.currency !== 'all') { | |
// if a specific currency is selected, filter the results | |
return hook.res.end(body['price'][hook.params.currency]); | |
} else { | |
// else, send all coin data back | |
hook.res.end(JSON.stringify(body)); |
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
module['exports'] = function echoHttp (hook) { | |
hook.debug("test messages are sent to the debug console"); | |
hook.debug(hook.params); | |
hook.debug(hook.req.path); | |
hook.debug(hook.req.method); | |
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
module['exports'] = function proxyHook (hook) { | |
hook.res.end('proxied'); | |
}; |
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
module['exports'] = function badTimeOutHook (hook) { | |
hook.res.write('hello'); | |
// never calls hook.res.end() | |
}; |
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
// gateway hook for running microservices on hook.io in real-time without an account | |
// example of deploying a js file to the hook.io cloud from the command line using cURL | |
// cat echo.js | curl --data-urlencode source@- http://gateway.hook.io | |
module['exports'] = function gatewayHook (hook) { | |
var mschema = require('mschema'); | |
var params = hook.params; | |
var source = params.source; |
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
module['exports'] = function echo (hook) { | |
// Access Node.js HTTP Request and Response objects | |
var req = hook.req, | |
res = hook.res; | |
// Use NPM Modules | |
var faker = require('faker'); | |
res.write('<strong>BYE BILLY</strong> '); | |
res.write(req.headers["x-forwarded-for"] + '<br/>'); | |
res.end(faker.hacker.phrase()); | |
}; |
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
module['exports'] = function (hook) { | |
hook.res.end('ended'); | |
}; | |
module['exports'].inputs = ['echo', 'echo', 'echo']; | |
module['exports'].outputs = ['echo', 'echo', 'echo']; |