Skip to content

Instantly share code, notes, and snippets.

@eugeniop
Last active May 1, 2017 23:53
Show Gist options
  • Save eugeniop/9fe84df8fcff6775d12b93d7eb5cafa8 to your computer and use it in GitHub Desktop.
Save eugeniop/9fe84df8fcff6775d12b93d7eb5cafa8 to your computer and use it in GitHub Desktop.
Flowroute WT Compiler
'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