| 1 |
= cowboy:set_env(3) |
| 2 |
|
| 3 |
== Name |
| 4 |
|
| 5 |
cowboy:set_env - Update a listener's environment value |
| 6 |
|
| 7 |
== Description |
| 8 |
|
| 9 |
[source,erlang] |
| 10 |
---- |
| 11 |
set_env(Name :: ranch:ref(), |
| 12 |
Key :: atom(), |
| 13 |
Value :: any()) |
| 14 |
-> ok |
| 15 |
---- |
| 16 |
|
| 17 |
Set or update an environment value for a previously started |
| 18 |
listener. |
| 19 |
|
| 20 |
This is most useful for updating the routes dynamically, |
| 21 |
without having to restart the listener. |
| 22 |
|
| 23 |
The new value will only be available to new connections. |
| 24 |
Pre-existing connections will still use the old value. |
| 25 |
|
| 26 |
== Arguments |
| 27 |
|
| 28 |
Name:: |
| 29 |
|
| 30 |
The name of the listener to update. |
| 31 |
+ |
| 32 |
The name of the listener is the first argument given to the |
| 33 |
link:man:cowboy:start_clear(3)[cowboy:start_clear(3)], |
| 34 |
link:man:cowboy:start_tls(3)[cowboy:start_tls(3)] or |
| 35 |
link:man:ranch:start_listener(3)[ranch:start_listener(3)] function. |
| 36 |
|
| 37 |
Key:: |
| 38 |
|
| 39 |
The key in the environment map. Common keys include `dispatch` |
| 40 |
and `middlewares`. |
| 41 |
|
| 42 |
Value:: |
| 43 |
|
| 44 |
The new value. |
| 45 |
+ |
| 46 |
The type of the value differs depending on the key. |
| 47 |
|
| 48 |
== Return value |
| 49 |
|
| 50 |
The atom `ok` is returned on success. |
| 51 |
|
| 52 |
An `exit:badarg` exception is thrown when the listener does |
| 53 |
not exist. |
| 54 |
|
| 55 |
== Changelog |
| 56 |
|
| 57 |
* *1.0*: Function introduced. |
| 58 |
|
| 59 |
== Examples |
| 60 |
|
| 61 |
.Update a listener's routes |
| 62 |
[source,erlang] |
| 63 |
---- |
| 64 |
Dispatch = cowboy_router:compile([ |
| 65 |
{'_', [ |
| 66 |
{"/", toppage_h, []}, |
| 67 |
{"/ws", websocket_h, []} |
| 68 |
]} |
| 69 |
]), |
| 70 |
|
| 71 |
cowboy:set_env(example, dispatch, Dispatch). |
| 72 |
---- |
| 73 |
|
| 74 |
== See also |
| 75 |
|
| 76 |
link:man:cowboy(3)[cowboy(3)], |
| 77 |
link:man:cowboy:start_clear(3)[cowboy:start_clear(3)], |
| 78 |
link:man:cowboy:start_tls(3)[cowboy:start_tls(3)], |
| 79 |
link:man:cowboy:get_env(3)[cowboy:get_env(3)], |
| 80 |
link:man:ranch:set_protocol_options(3)[ranch:set_protocol_options(3)] |