如何使用Node.js和express设置Google Domains动态DNS?

时间:2019-06-04 01:03:57

标签: node.js express dns

我已经在Raspberry Pi运行Express上建立了Node.Js网站。

我想使用动态DNS从Node.JS / Express更新我的Google DNS域

我尝试过的事情:

Management Assistant

使用curl命令看起来像这样:

function domainUpdate() { console.log(`[SERVER] Posting to Google's Servers...`) let username = process.env.USERNAME || ``; let password = process.env.PASSWORD || ``; let hostname = process.env.HOSTNAME || ``; let url = `https://${username}:${password}@domains.google.com/nic/update?hostname=${hostname}`; https.request(url, (res) => { console.log(`status - ${res.statusCode}`); console.log(`output - ${res.complete}`) }).on("error", (e) => { if (e) throw e })

除了“ [SERVER]正在发布到Google的服务器...”之外没有任何输出

1 个答案:

答案 0 :(得分:0)

尝试进行Axios之类的操作来发出实际的请求。它为您处理了很多繁重的工作:

const axios = require('axios');

function domainUpdate() {
    console.log(`[SERVER] Posting to Google's Servers...`)
    let username = process.env.USERNAME || ``;
    let password = process.env.PASSWORD || ``;
    let hostname = process.env.HOSTNAME || ``;
    let url = `https://${username}:${password}@domains.google.com/nic/update?hostname=${hostname}`;

    axios.get(url)
    .then(res => {
      console.log(`status - ${res.status}`);
      console.log(`output - ${res.data}`);
    })
    .catch(err => {
      throw err;
    })
}

只要请求的格式正确,该端点看起来就返回200。链接到的Google support article列出了可能的响应,这些响应将在Axios响应对象的data属性中。