Packages

A wrapper around Ngrok providing a secure tunnel to localhost for demoing your Elixir/Phoenix web application or testing webhook integrations.

Current section

Files

Jump to
ex_ngrok lib executable.ex
Raw

lib/executable.ex

defmodule Ngrok.Executable do
@moduledoc """
Spawns a foreign process that will be terminated when the application stops
- See: https://shift.infinite.red/foreign-processes-and-phoenix-555179c24151#.at6f31kd4
"""
use GenServer
def start_link do
GenServer.start_link(__MODULE__, :ok, name: __MODULE__)
end
def init(:ok) do
port = Port.open(
{:spawn, "#{Path.dirname(__ENV__.file)}/../bin/wrap #{ngrok}"},
[])
{:ok, port}
end
@spec ngrok :: String.t
defp ngrok do
arguments = [
Application.get_env(:ex_ngrok, :executable),
Application.get_env(:ex_ngrok, :protocol),
Application.get_env(:ex_ngrok, :port),
]
Enum.join(arguments, " ")
end
end