View Source CozyProxy (cozy_proxy v0.1.2)

Proxy requests to other plugs.

usage

Usage

Set base configurations within config files:

config :demo_app, CozyProxy,
  [
    http: [port: 8080],
    backends: [
      %{
        plug: SubAppWeb.Endpoint,
        domain: "site1.example.com"
      },
      %{
        plug: {DemoPlug, []},
        domain: "site2.example.com"
      }
    ]
  ]

CozyProxy instances are isolated supervision trees and you can include it in application's supervisor.

Use the application configuration you've just set and include CozyProxy in the list of supervised children:

# lib/demo_app/application.ex
def start(_type, _args) do
  children = [
    # ...
    {CozyProxy, Application.fetch_env!(:demo_app, CozyProxy)}
  ]

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

When using CozyProxy, it's better to configure Phoenix endpoints to not start servers, in order to avoid Phoenix endpoints bypassing CozyProxy:

config :demo_app, SubAppWeb.Endpoint, server: false

available-options-of-configuration

Available options of configuration

  • :http - the configuration for the HTTP server. It accepts all options as defined by Plug.Cowboy.
  • :https - the configuration for the HTTPS server. It accepts all options as defined by Plug.Cowboy.
  • :server - true by default. If you are running the application with mix phx.server, this option is ignored, and the server will always be started.
  • :backends - the configuration of backends:
    • :plug
    • :domain
    • :verb
    • :host
    • :path

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.