安装ngrok
$ brew search ngrok
==> Casks
ngrok ✔
If you meant "ngrok" specifically:
Upstream sunsetted 1.x in March 2016 and 2.x is not open-source.
If you wish to use the 2.x release you can install with Homebrew Cask:
brew cask install ngrok
我们需要安装 ngrok cask
$ brew cask install ngrok
好了。安装完毕
此时我们需要本地起一个 http 服务。
package main
import (
"io"
"net/http"
"log"
)
// hello world, the web server
func HelloServer(w http.ResponseWriter, req *http.Request) {
io.WriteString(w, "hello, world!\n")
}
func main() {
http.HandleFunc("/hello", HelloServer)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
我们使用 golang http 起了一个 server 服务。 端口为 8080。 此时我们需要ngrok 去监听本地 8080 端口即可。
$ ngrok http 127.0.0.1:8080
此时我们需要观察 Session Status 的值 为 online 就表示可以外网访问了。 我们可以通过 http://127.0.0.1:4040 网页端查看。
此时我们就可以很方便的联调了。例如支付。。。
原文链接:www.zhanggaoyuan.com/article/21
原文标题:[mac 使用 ngrok 搭建外网服务]
本站使用「 署名-非商业性使用 4.0 国际 (CC BY-NC 4.0)」创作共享协议,转载或使用请署名并注明出处。