Skip to content

Instantly share code, notes, and snippets.

@jaemyeong
Last active July 8, 2022 07:17
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 jaemyeong/82c87931d8a66a7c0f76529ac1f5fb90 to your computer and use it in GitHub Desktop.
Save jaemyeong/82c87931d8a66a7c0f76529ac1f5fb90 to your computer and use it in GitHub Desktop.
DigitalOcean DNS Update
#!/usr/bin/env zx
import os from 'os';
$.verbose = false;
const networkInterfaces = os.networkInterfaces();
const externalAddress = Object.values(networkInterfaces).flatMap(value => value).find(value => value.family === 'IPv4' && value.internal === false).address;
echo`${externalAddress}`;
const response = await fetch(`https://api.digitalocean.com/v2/domains/${argv.domainName}/records/${argv.recordId}`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${argv.token}`
},
body: JSON.stringify({
data: externalAddress
})
})
echo`${response.status}`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment