簡體   English   中英

如何使用 Google 計算 node.js api 創建具有公共 IP 地址的接口?

[英]How do you create an interface with a public IP address with Google compute node.js api?

我使用谷歌官方api: https : //www.npmjs.com/package/@google-cloud/compute

有一些示例,但沒有顯示如何使用公共 IP 創建接口。

我不能使用http:true因為我需要打開一個特定的 TCP 端口。

創建防火牆規則以允許連接到 VM 公共 IP 上的端口。

參考自: https : //googleapis.dev/nodejs/compute/latest/Network.html#createFirewall

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const network = compute.network('network-name');

const config = {
  protocols: {
    tcp: [3000],
    udp: [] // An empty array means all ports are allowed.
  },

  ranges: ['0.0.0.0/0']
};

function callback(err, firewall, operation, apiResponse) {
  // `firewall` is a Firewall object.

  // `operation` is an Operation object that can be used to check the status
  // of the request.
}

network.createFirewall('new-firewall-name', config, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
network.createFirewall('new-firewall-name', config).then(function(data) {
  const firewall = data[0];
  const operation = data[1];
  const apiResponse = data[2];
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM