【发布时间】:2021-01-17 04:56:56
【问题描述】:
我用的是谷歌官方api:https://www.npmjs.com/package/@google-cloud/compute
有示例,但没有显示如何使用公共 IP 创建接口。
我不能使用http:true,因为我需要打开一个特定的 TCP 端口。
【问题讨论】:
标签: node.js api google-cloud-platform google-compute-engine
我用的是谷歌官方api:https://www.npmjs.com/package/@google-cloud/compute
有示例,但没有显示如何使用公共 IP 创建接口。
我不能使用http:true,因为我需要打开一个特定的 TCP 端口。
【问题讨论】:
标签: node.js api google-cloud-platform google-compute-engine
创建防火墙规则以允许连接到 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];
});
【讨论】: