Created
November 13, 2017 10:44
-
-
Save michalczukm/93700769f50d3e516b9e0d30f7c1d894 to your computer and use it in GitHub Desktop.
Azure function - ask for my current IP
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
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