Money.Input.Visualizer.Standalone (Money.Input v0.1.0)

View Source

A tiny helper that runs Money.Input.Visualizer as a standalone web server for local development.

Requires :bandit in your project's deps. This module is only compiled when :bandit is present — without it, Money.Input.Visualizer.Standalone doesn't exist and calling its functions raises UndefinedFunctionError.

Money.Input.Visualizer.Standalone.start(port: 4002)
# Visit http://localhost:4002

To stop the server, call Money.Input.Visualizer.Standalone.stop/1 with the PID returned from start/1.

Enable flag

For safety, this helper refuses to start unless the visualizer has been enabled — either via config:

config :ex_money_input, visualizer: true

…or by passing enabled: true to start/1 explicitly. The intent is to make accidental deployment of a developer tool to production loud rather than silent. Mounting Money.Input.Visualizer directly under forward/2 in a host Phoenix router bypasses this — that path is up to the host to gate.

Summary

Functions

Returns a child spec suitable for embedding under a supervision tree.

Returns true when the visualizer is enabled via config or via the :enabled option.

Starts the visualizer on the given port.

Stops a standalone server started by start/1.

Functions

child_spec(options \\ [])

@spec child_spec(keyword()) :: Supervisor.child_spec()

Returns a child spec suitable for embedding under a supervision tree.

Honours the same enable-flag rules as start/1. When the flag is off, the child spec is a no-op task that exits :normal, so a supervisor with a permanent restart strategy won't keep retrying.

Options

See start/1.

Returns

  • A child specification map.

enabled?(options \\ [])

@spec enabled?(keyword()) :: boolean()

Returns true when the visualizer is enabled via config or via the :enabled option.

start(options \\ [])

@spec start(keyword()) :: {:ok, pid()} | {:error, term()}

Starts the visualizer on the given port.

Options

  • :port — TCP port to listen on. Default 4002.

  • :ip — IP address to bind to. Default :loopback (only accessible from localhost). Pass :any to bind on all interfaces.

  • :enabled — when true, override the :ex_money_input, :visualizer config check. Default false.

Returns

  • {:ok, pid} on success.

  • {:error, %Money.Input.VisualizerDisabledError{}} when the visualizer has not been enabled. See the module doc.

  • {:error, reason} on other failures (e.g. port-in-use).

Examples

iex> Application.put_env(:ex_money_input, :visualizer, true)
iex> {:ok, pid} = Money.Input.Visualizer.Standalone.start(port: 0)
iex> :ok = Money.Input.Visualizer.Standalone.stop(pid)

stop(pid)

@spec stop(pid()) :: :ok

Stops a standalone server started by start/1.

Arguments

  • pid — the process identifier returned by start/1.

Returns

  • :ok.