【问题标题】:Use localtunnel and pass generated url to node command使用 localtunnel 并将生成的 url 传递给节点命令
【发布时间】:2018-01-11 06:35:35
【问题描述】:

我希望在端口 4000 上使用 ngrok,这是一个将导出 Forwarding URL 的命令。每次运行时都会随机生成一个新的 URL。

我想将该 URL http://2e1v870f.ngrok.io 传递给 node process.env 变量,而不是每次都对其进行硬编码。

例如在 bash 中:

ngrok http 4000 | <process/define_something> | FORWARDING={something} node index.js

另外,这些是在两个正在运行的进程中,我使用npm-run-all 来执行类似的操作。 https://www.npmjs.com/package/npm-run-all

ngrok by @inconshreveable                                                                                                                                            (Ctrl+C to quit)

Session Status                online                                                                                                                                                 
Version                       2.2.8                                                                                                                                                  
Region                        United States (us)                                                                                                                                     
Web Interface                 http://127.0.0.1:4041                                                                                                                                  
Forwarding                    http://2e1v870f.ngrok.io -> localhost:4000                                                                                                             
Forwarding                    https://2e1v870f.ngrok.io -> localhost:4000                                                                                                            

Connections                   ttl     opn     rt1     rt5     p50     p90                                                                                                            
                              0       0       0.00    0.00    0.00    0.00                                                                                                           

【问题讨论】:

    标签: node.js bash ngrok


    【解决方案1】:

    我已转而使用node wrapper 代替ngrok,因为我无法访问 bash 的输出。这是一个例子start.js

    if (!process.env.ROOT_URL) {
      var ngrok = require('ngrok');
      var shell = require('shelljs');
    
      ngrok.connect(3000, function(err, url) {
        shell.exec('ROOT_URL=' + url + ' meteor --settings settings.json', function(code, stdout, stderr) {
          console.log('Exit code:', code);
          console.log('Program output:', stdout);
          console.log('Program stderr:', stderr);
        });
      });
    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-20
      • 2017-07-01
      • 1970-01-01
      • 2022-11-18
      • 1970-01-01
      • 2020-02-18
      • 1970-01-01
      • 2022-01-13
      相关资源
      最近更新 更多