Git Product home page Git Product logo

ngrokker's Introduction

ngrokker

GoDoc

ngrokker wraps the ngrok shell command, allowing you to programmatically create an introspective tunnel. For more information about ngrok, see https://ngrok.com.

Created for the send2phone utility.

This package is in alpha state. Contributions are welcome and encouraged!

Prerequisites

You must have ngrok installed and available on your $PATH. See https://ngrok.com/download.

Installing

This package is go getable.

go get github.com/mfresonke/ngrokker

Example Usage

Code

package main

import (
	"fmt"
	"io/ioutil"
	"net/http"

	"github.com/mfresonke/ngrokker"
)

func main() {
	// setup an introspective tunnel to port 8080
	tunnel := ngrokker.NewHTTPTunnel(true, false)
	endpoints, _ := tunnel.Open(8080)
	// don't forget to close the tunnel!
	defer tunnel.Close()

	// set up a http server to respond to requests on port 8080
	http.HandleFunc("/hello-world", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Thanks, @inconshreveable!")
	})
	go func() {
		http.ListenAndServe(":8080", nil)
	}()

	// find the secure endpoint out of the two ngrok creates by default
	var secureEndpoint ngrokker.Endpoint
	for i, endpoint := range endpoints {
		fmt.Println("Endpoint", i+1, "-", endpoint.URL)
		if endpoint.Secure {
			secureEndpoint = endpoint
		}
	}

	// Make a zero-configuration https request to your own machine!
	// Notice the lack of ":8080"!
	reqURL := secureEndpoint.URL + "/hello-world"
	fmt.Println("Making request from outside world to", reqURL)
	resp, _ := http.Get(reqURL)
	defer resp.Body.Close()
	bodyBytes, _ := ioutil.ReadAll(resp.Body)
	fmt.Println(string(bodyBytes))
}

Output

Endpoint 1 - https://9545bfed.ngrok.io
Endpoint 2 - http://9545bfed.ngrok.io
Making request from outside world to https://9545bfed.ngrok.io/hello-world
Thanks, @inconshreveable!

Issues

See https://github.com/mfresonke/ngrokker/issues

Contributing

Please fork the repo, make your changes, and create a PR. Make sure you gofmt, golint, and go vet your code!

Notice

All users of ngrok MUST accept the ngrok terms of service before opening a tunnel.

ngrokker's People

Contributors

mfresonke avatar

Watchers

 avatar

ngrokker's Issues

ngrokker does not enable paid account behavior

With a paid ngrokker account, you can do some more things, such as open multiple instances of ngrok at the same time. Due to the fact that myself (and probably >90% of users) do not have a paid ngrok account, this was of low priority.

ngrokker uses a package variable to detect concurrent usage

This is not ideal. Ideally, we either get error feedback from ngrok itself (relatively simple, but not foolproof), or better, we search for the ngrok process and react accordingly. (doable, but is platform specific and more complex). Anyone willing to tackle this issue is welcome to do so.

ngrokker does not check ngrok version

in its current state, ngrokker does not check for the ngrok version before attempting to open the tunnel. While this should be fine for 2.X.X releases, is a definite problem if someone still has a 1.X.X release installed.

ngrokker does not properly detect an ngrok process started outside of package

if you start ngrok outside of the package (e.g. through your shell), the package does not detect this correctly, and may return an incorrect slice of Endpoints and a nil error.

While you may see some attempts in the code to do this, unfortunately it does not work. It used to work when the process was ran in a different way (using cmd.CombinedOutput IIRC), but it stopped working and I don't have the time to track down why. If anyone wants to give this a shot, by all means!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.