Last active
June 27, 2017 08:52
-
-
Save thameera/899ee1d7c3a845df24136b16c00638ab to your computer and use it in GitHub Desktop.
wt compiler for zendesk+auth0 extend integration demo
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'; | |
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