Skip to content

Instantly share code, notes, and snippets.

@jczimm
Last active June 29, 2016 13:10
Show Gist options
  • Save jczimm/dbe425d34709149ba209 to your computer and use it in GitHub Desktop.
Save jczimm/dbe425d34709149ba209 to your computer and use it in GitHub Desktop.
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);
}
});
});
}
@jczimm
Copy link
Author

jczimm commented Dec 30, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment