View Source Plug.CGI (plug_cgi v0.1.4)

Primary public module for plug_cgi. See run/1 below for the main entrypoint of plug_cgi.

This module can also be used in a supervisor since it provides a child_spec/1

children = [
  {Plug.CGI, splug: MyPlug, options: [log_device: :stdio]}
]

opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)

Link to this section Summary

Functions

The entrypoint of Plug.CGI, called to start the Plug chain starting with plug.

Link to this section Functions

@spec run(atom(), Keyword.t()) :: Plug.Conn.t()

The entrypoint of Plug.CGI, called to start the Plug chain starting with plug.

The log_device option sets the default device for Logger.Backends.Console, defaults to :standard_error. The output_device option sets the default output for the CGI response, defaults to :stdio.

The opts argument is also passed along to Plug.init/1 for the given plug and call_opts option will be passed into Plug.call/2 for the given plug.

example

Example

defmodule MyPlug do
  import Plug.Conn

  def init(options), do: options

  def call(conn, _opts) do
    conn
    |> put_resp_content_type("text/plain")
    |> send_resp(200, "Hello world")
  end
end

Plug.CGI.run MyPlug