Skip to content

Instantly share code, notes, and snippets.

@ma2shita
Created November 12, 2019 08:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ma2shita/e2391a03613442296a9d6dc2a72650c0 to your computer and use it in GitHub Desktop.
const http = require('https');
module.exports = function (context, req) {
context.log(req);
const url = process.env[`WEBHOOK_URL`];
const postBody = req.rawBody;
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postBody)
}
};
const client = http.request(url, options, (res) => {
context.log(res.statusCode);
context.log(res.headers);
let resBody = '';
res.on('data', (chunk) => { resBody += chunk; });
res.on('end', () => {
context.log(resBody);
context.res = {status: 204};
context.done();
});
});
client.on('error', (e) => {
context.log.error(e);
context.res = {status: 500};
context.done();
});
client.write(postBody);
client.end();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment