如何生成固定的网址与 ngrok

我在研究 Facebook Messenger。

Facebook 应用程序只接受一个 webhook 的 URL,但是 Ngrock每次都会生成新的 URL。现在我无法测试我的应用程序,因为 webhook 网址改变。

146253 次浏览

You need to set up auth token. You can find it here https://dashboard.ngrok.com/auth. (W̶o̶r̶k̶s̶ ̶w̶i̶t̶h̶ ̶f̶r̶e̶e̶ ̶v̶e̶r̶s̶i̶o̶n̶,̶ ̶n̶o̶ ̶n̶e̶e̶d̶ ̶t̶o̶ ̶p̶a̶y̶ it's now paid feature, see ngrok pricing).

Then you can use it like this:

ngrok http 80 --subdomain yoursubdomain

No more free subdomain support from ngrok.....pls have a error as below

Tunnel session failed: Only paid plans may bind custom subdomains. Failed to bind the custom subdomain 'arvindpattartestfb.ngrok.io' for the account 'arvccccc'. This account is on the 'Free' plan.

Upgrade to a paid plan at: https://dashboard.ngrok.com/billing/plan

ERR_NGROK_313

Though its not a solution but take it as workaround, I had the same problem while testing. What i did is keep the ngrok running with my http port, so my ngrok url is not changing. but I frequently changing and restarting my server for testing and debugging.

UPDATE May 2020

Serveo is up and running again! No installation, no signup!

All you need to do is to run this:

ssh -R <unique subdomain>:80:<your local host>:<your local port> serveo.net

like

ssh -R youruniquesubdomain:80:localhost:8000 serveo.net

UPDATE January 2020

Since there are some issues with Serveo and localtunnel, I want to share with you another free ssh-based self-hosting service: Localhost.run

Unfortunately, it does not provide unique subdomains but it is ssh-based so you do not have to install additional applications. Still waiting for Serveo coming back.


UPDATE April 2018

I've found Serveo just now! And it is totally incredible!


UPDATE November 2017

Probably, it is not the best option for you but I started using localtunnel instead of ngrok.

An installation and run flow is very simple:

npm install -g localtunnel
lt --port <your localhost port> --subdomain youruniquesubdomain

Then I can go to my http://youruniquesubdomain.localtunnel.me That's it!

For DHIS2 local installation, I did this on the terminal on ubuntu server.

Make sure your web is running on the specified port. Mine was on 8080.

ssh -R dani.serveo.net:80:localhost:8080 serveo.net

The beauty of this serveo.net is you can reuse the same hostname prefix url before serveo.net as many time as you want, even if power goes off or internet diconnection.

Neither localtunnel.me or Serveo are working for me right now so I created a temporary solution that works for some use-cases including mine (react-native local development): using the ngrok npm package one can save the generated ngrok url into a json file, and that file can be read for any other app.

First make sure to install ngrok using npm install ngrok then use this node script:

const ngrok = require('ngrok');
const fs = require('fs').promises;


(async function() {
const url = await ngrok.connect(3000);
const api = ngrok.getApi();
let data = await api.get('api/tunnels');
data = JSON.parse(data);
let dict = {'domain': data.tunnels[0].public_url}
await fs.writeFile("config.json", JSON.stringify(dict));
console.log("saved " + data.tunnels[0].public_url);
})();


Then from your app you may read it using code similar or equal to:

const backend = require('./config.json').domain;

Staqlab tunnel is providing domain for free. Its works great but need a binary to be downloaded from there website. Using this service for month without any hassle