Skip to content

Instantly share code, notes, and snippets.

@kellysutton
Created June 29, 2017 05:11
Show Gist options
  • Save kellysutton/5523523d25583471ed041b054100b41a to your computer and use it in GitHub Desktop.
Save kellysutton/5523523d25583471ed041b054100b41a to your computer and use it in GitHub Desktop.
'use strict';
const http = require('https');
// Forward the button press onto our Heroku app
// as a POST request with a JSON body.
exports.handler = (event, context, callback) => {
const params = {
serialNumber: event.serialNumber,
event: event
};
const postData = JSON.stringify(params);
const req = http.request({
hostname: 'my-app-name.herokuapp.com',
port: 443,
path: '/button-presses',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData)
}
}, (res) => {
res.on('end', function() {
context.done(null);
});
})
req.write(postData);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment