cowboy.set_env.asciidoc 1.6 KB

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