Last active
May 27, 2017 15:58
-
-
Save azureru/5d23bf3662f903754c53196ff220bfc3 to your computer and use it in GitHub Desktop.
Node-red Dyndns using digitalocean
This file contains hidden or 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
// the node-script | |
var request = global.get('request'); | |
var accessToken = "YOURACCESSTOKEN"; | |
var domain = "YOURDOMAIN"; | |
var record = "YOURDNSRECORD"; | |
var ip = msg.payload; | |
var options = { | |
method: 'PUT', | |
url: 'https://api.digitalocean.com/v2/domains/'+ domain +'/records/' + record, | |
headers: { | |
'User-Agent' : 'request', | |
'Content-Type' : 'application/json', | |
'Authorization' : 'Bearer ' + accessToken | |
}, | |
body : '{"data" : "'+ip+'"}' | |
}; | |
request(options, function (error, response, body) { | |
if (!error && response.statusCode == 200) { | |
// no error - update successfull | |
node.status({fill:"green",shape:"dot",text: ip}); | |
node.send({payload : body}); | |
} else { | |
node.status({fill:"red",shape:"dot",text: 'Error'}); | |
} | |
}); | |
return; |
This file contains hidden or 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
{ | |
// add this to your config/setting. don't forget to npm install these modules first | |
functionGlobalContext: { | |
os:require('os'), | |
request:require('request'), | |
cheerio:require('cheerio'), | |
async:require('async') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment