Skip to content

Instantly share code, notes, and snippets.

@michalczukm
Created November 13, 2017 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michalczukm/93700769f50d3e516b9e0d30f7c1d894 to your computer and use it in GitHub Desktop.
Save michalczukm/93700769f50d3e516b9e0d30f7c1d894 to your computer and use it in GitHub Desktop.
Azure function - ask for my current IP
const https = require('https');
module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
https.get('https://ifconfig.co/json', res => {
res.setEncoding('utf8');
let body = '';
res.on('data', data => {
body += data;
});
res.on('end', () => {
context.res = {
body: JSON.parse(body),
headers: {
'Content-Type': 'application/json'
}
}
context.done();
})
}).on('error', function (e) {
context.res = {
status: 400,
body: 'problem with request: ' + e.message
}
context.done();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment