cowboy:set_env(3)

NAME

cowboy:set_env - Update a listener's environment value

DESCRIPTION
    set_env(Name  :: ranch:ref(),
            Key   :: atom(),
            Value :: any())
        -> ok

Set or update an environment value for a previously started listener.

This is most useful for updating the routes dynamically, without having to restart the listener.

The new value will only be available to new connections. Pre-existing connections will still use the old value.

ARGUMENTS

Name
    The name of the listener to update.

    The name of the listener is the first argument given to the cowboy:start_clear(3), cowboy:start_tls(3) or ranch:start_listener(3) function.

Key
    The key in the environment map. Common keys include dispatch and middlewares.

Value
    The new value.

    The type of the value differs depending on the key.

RETURN VALUE

The atom ok is returned on success.

An exit:badarg exception is thrown when the listener does not exist.

CHANGELOG
    • 1.0: Function introduced.

EXAMPLES

Update a listener's routes
    Dispatch = cowboy_router:compile([
        {'_', [
            {"/", toppage_h, []},
            {"/ws", websocket_h, []}
        ]}
    ]),

    cowboy:set_env(example, dispatch, Dispatch).

SEE ALSO

cowboy(3), cowboy:start_clear(3), cowboy:start_tls(3), cowboy:get_env(3), ranch:set_protocol_options(3)