-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
40 lines (37 loc) · 981 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const DnsManagementClient = require('azure-arm-dns');
const msRestAzure = require("ms-rest-azure");
const express = require('express');
const site = express();
const subscriptionId = '<---->';
const resourcesGroup = '<---->';
const zoneName = '<---->';
let dnsClient = null;
site.post('/update_dns', (req, res) => {
if (!req.query.ip_addr) {
res.send({ status: 'ok' });
} else {
dnsClient.recordSets.update(resourcesGroup, zoneName, 'prefix.', 'A', {
aRecords: [{
ipv4Address: req.query.ip_addr
}]
}).then((response) => {
res.send({
status: 'ok',
azure_response: response,
});
}).catch((error) => {
res.send({
status: 'error',
azure_error: error,
});
})
}
});
msRestAzure.interactiveLogin({
domain: '<---->'
}).then((creds) => {
dnsClient = new DnsManagementClient(creds, subscriptionId);
site.listen(3399, '127.0.0.1');
}).catch((error) => {
console.error(error);
})