Skip to content

Instantly share code, notes, and snippets.

@thameera
Last active June 27, 2017 08:52
Show Gist options
  • Save thameera/899ee1d7c3a845df24136b16c00638ab to your computer and use it in GitHub Desktop.
Save thameera/899ee1d7c3a845df24136b16c00638ab to your computer and use it in GitHub Desktop.
wt compiler for zendesk+auth0 extend integration demo
'use strict';
module.exports = (options, cb) => {
console.log('a');
options.nodejsCompiler(options.script, (e, Func) => {
console.log('b');
if (e) return cb(e);
console.log('c');
let instance = new Func();
instance.secrets = options.secrets;
instance.meta = options.meta;
return cb(null, (ctx, req, res) => {
console.log('d');
let method = 'onTrigger';
if (typeof instance[method] !== 'function') {
let error = new Error(`Unuspported trigger: ${method}.`);
error.statusCode = 501;
return cb(error);
}
else {
if (instance[method].length === 1) res.end();
req.on('data', function (data) {
var json = JSON.parse(data);
return instance[method](json, res);
});
}
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment