Last active
June 29, 2016 13:10
-
-
Save jczimm/dbe425d34709149ba209 to your computer and use it in GitHub Desktop.
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 jczimmCLI (hook) { | |
var request = require('request'); | |
var http = require('http') | |
, vm = require('vm') | |
, concat = require('concat-stream'); | |
request.get("https://npmcdn.com/hget@3.0.0/index.js", function(err, res, body) { | |
var sandbox = { require: require }; | |
vm.createContext(sandbox); | |
vm.runInThisContext(body, './remote_modules/hget.js', sandbox); | |
var hget = require('./remote_modules/hget.js'); | |
request.get("http://jczimm.com/" + hook.req.url, function(err, res, body) { | |
if (!err && res.statusCode.toString()[0] !== "2") { | |
var plaintext = hget(body); | |
hook.res.writeHead(res.statusCode, { | |
'Content-Length': plaintext.length, | |
'Content-Type': 'text/plain' | |
}); | |
hook.res.end(plaintext); | |
} else { | |
hook.res.statusCode = res.statusCode; | |
hook.res.end(err); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://hook.io/jczimm/jczimm-cli
Broken at the moment; latest version of "hget" requires a version of "htmlmd-2", which requires a version of "jsdom", which requires ES2015 compatibility (and nodejs version 4+)...
If possible to require an older version of "hget", that could fix this.