@achingbrain/ngrok 中文文档教程

发布于 9年前 浏览 19 项目主页 更新于 3年前

ngrok Build Status

alt ngrok.com

Ngrok 将您的本地主机暴露给网络。 https://ngrok.com/

usage

NPM

它将为您的平台下载 ngrok 2.0 二进制文件并将其放入 bin 文件夹中。 您还可以全局安装 ngrok 并直接从 bash 中使用它

$ npm install ngrok -g
$ ngrok http 8080

connect

var ngrok = require('ngrok');

ngrok.connect(function (err, url) {}); // https://757c1652.ngrok.io -> http://localhost:80
ngrok.connect(9090, function (err, url) {}); // https://757c1652.ngrok.io -> http://localhost:9090
ngrok.connect({proto: 'tcp', addr: 22}, function (err, url) {}); // tcp://0.tcp.ngrok.io:48590
ngrok.connect(opts, function(err, url) {});

首先连接会生成 ngrok 进程,因此每个下一个隧道的创建速度要快得多。

options

ngrok.connect({
    proto: 'http', // http|tcp|tls
    addr: 8080, // port or network address
    auth: 'user:pwd', // http basic authentication for tunnel
    subdomain: 'alex', // reserved tunnel name https://alex.ngrok.io,
    authtoken: '12345' // your authtoken from ngrok.com
}, function (err, url) {});

其他选项:name、inspect、host_header、bind_tls、hostname、crt、key、c​​lient_cas、remote_addr - 阅读此处

disconnect

节点进程完成后,ngrok 和所有隧道将被终止。 要停止隧道,请使用

ngrok.disconnect(url); // stops one
ngrok.disconnect(); // stops all
ngrok.kill(); // kills ngrok process

authtoken

ngrok.com 服务的许多高级功能需要您注册一个帐户并使用 authtoken。 您指定的 authtoken 与您用于 ngrok 1.0 - 0.2 之前的模块版本的不同。 您的 2.0 ngrok authtoken 在您的 ngrok 2.0 仪表板上可用。

您可以将它作为每个 connect 的选项传递,或者为更多隧道设置一次 <代码>javascript ngrok.authtoken(令牌,函数(错误,令牌){});

## emitter
Also you can use ngrok as an event emitter, it fires "connect", "disconnect" and "error" events

javascript ngrok.once('connect', function (url) {}; ngrok.connect(端口);

## configs
You can use ngrok's [configurations files](https://ngrok.com/docs#config), then just pass `name` option when making a tunnel

OS X /Users/example/.ngrok2/ngrok.yml Linux /home/example/.ngrok2/ngrok.yml Windows C:\Users\example.ngrok2\ngrok.yml ```

inspector

建立隧道后,您可以使用 ngrok 接口 http://127.0.0.1:4040 检查通过 ngrok 完成的 webhook。

ngrok Build Status

alt ngrok.com

Ngrok exposes your localhost to the web. https://ngrok.com/

usage

NPM

It will download the ngrok 2.0 binary for your platform and put it into the bin folder. You can also install ngrok globally and use it directly from bash

$ npm install ngrok -g
$ ngrok http 8080

connect

var ngrok = require('ngrok');

ngrok.connect(function (err, url) {}); // https://757c1652.ngrok.io -> http://localhost:80
ngrok.connect(9090, function (err, url) {}); // https://757c1652.ngrok.io -> http://localhost:9090
ngrok.connect({proto: 'tcp', addr: 22}, function (err, url) {}); // tcp://0.tcp.ngrok.io:48590
ngrok.connect(opts, function(err, url) {});

First connect spawns the ngrok process so each next tunnel is created much faster.

options

ngrok.connect({
    proto: 'http', // http|tcp|tls
    addr: 8080, // port or network address
    auth: 'user:pwd', // http basic authentication for tunnel
    subdomain: 'alex', // reserved tunnel name https://alex.ngrok.io,
    authtoken: '12345' // your authtoken from ngrok.com
}, function (err, url) {});

Other options: name, inspect, host_header, bind_tls, hostname, crt, key, client_cas, remote_addr - read here

disconnect

The ngrok and all tunnels will be killed when node process is done. To stop the tunnels use

ngrok.disconnect(url); // stops one
ngrok.disconnect(); // stops all
ngrok.kill(); // kills ngrok process

authtoken

Many advanced features of the ngrok.com service require that you sign up for an account and use authtoken. The authtoken you specify is not the same as the one you used for ngrok 1.0 - module versions prior to 0.2. Your 2.0 ngrok authtoken is available on your ngrok 2.0 dashboard.

You can pass it as option with each connect or set it once for further tunnels javascript ngrok.authtoken(token, function(err, token) {});

## emitter
Also you can use ngrok as an event emitter, it fires "connect", "disconnect" and "error" events

javascript ngrok.once('connect', function (url) {}; ngrok.connect(port);

## configs
You can use ngrok's [configurations files](https://ngrok.com/docs#config), then just pass `name` option when making a tunnel

OS X /Users/example/.ngrok2/ngrok.yml Linux /home/example/.ngrok2/ngrok.yml Windows C:\Users\example.ngrok2\ngrok.yml ```

inspector

When tunnel is established you can use the ngrok interface http://127.0.0.1:4040 to inspect the webhooks done via ngrok.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文