View Source SiteEncrypt.Phoenix.Endpoint (site_encrypt v0.6.0)
SiteEncrypt
adapter for Phoenix endpoints.
Usage
- Replace
use Phoenix.Endpoint
withuse SiteEncrypt.Phoenix.Endpoint
- Add the implementation of
SiteEncrypt.certification/0
to the endpoint (the@behaviour SiteEncrypt
is injected when this module is used).
See __using__/1
for details.
Summary
Functions
Turns the module into a Phoenix Endpoint certified by site_encrypt.
Returns a specification to start this module under a supervisor.
Starts the endpoint managed by SiteEncrypt
.
Types
Functions
Turns the module into a Phoenix Endpoint certified by site_encrypt.
This macro will add use Phoenix.Endpoint
and @behaviour SiteEncrypt
to the caller module.
It will also provide the default implementation of SiteEncrypt.handle_new_cert/0
.
The macro accepts the following options:
:otp_app
- Same as withPhoenix.Endpoint
, specifies the otp_app running the endpoint. Any app env endpoint options must be placed under that app.:endpoint_opts
- Endpoint options which are deep merged on top of options defined in app config.
The macro generates the child_spec/1
function, so you can list your endpoint module as a
supervisor child. In addition, you can pass additional endpoint options with {MyEndpoint, opts}
,
where opts
is standard
Phoenix endpoint configuration.
The final endpoint config is assembled in the following order:
- Options provided in config.exs and runtime.exs (via
config :my_app, MyEndpoint, [...]
) - Options provided via
use SiteEncrypt.Phoenix.Endpoint, endpoint_opts: [...]
- Options provided via
{MyEndpoint, opts}
.
Overriding child_spec
To provide config at runtime and embed it inside the endpoint module, you can override the
child_spec/1
function:
defmodule MyEndpoint do
use SiteEncrypt.Phoenix.Endpoint, otp_app: :my_app
defoverridable child_spec: 1
def child_spec(_arg) do
# invoked at runtime, before the endpoint is first started
# builds endpoint config at runtime
endpoint_config = [
http: [...],
https: [...],
...
]
# Invokes the base implementation with the built config. This will be merged on top of
# options provided via `use SiteEncrypt.Phoenix.Endpoint` and app config.
super(endpoint_config)
end
...
end
@spec child_spec(start_opts()) :: Supervisor.child_spec()
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec start_link(start_opts()) :: Supervisor.on_start()
Starts the endpoint managed by SiteEncrypt
.