Last active
May 1, 2017 23:53
-
-
Save eugeniop/9fe84df8fcff6775d12b93d7eb5cafa8 to your computer and use it in GitHub Desktop.
Flowroute WT Compiler
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
'use strict'; | |
module.exports = (options, cb) => { | |
options.nodejsCompiler(options.script, (e, Func) => { | |
if (e) return cb(e); | |
let instance = new Func(); | |
instance.secrets = options.secrets; | |
instance.meta = options.meta; | |
return cb(null, (ctx, req, res) => { | |
let method = 'onSMS'; | |
if (typeof instance[method] !== 'function') { | |
let error = new Error(`Unuspported event: ${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); // I can't parse it because, it's a string. why? | |
return instance[method](json, res); | |
}); | |
} | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment