Module nh_url

Work out the socket URL to connect to.

Description

Work out the socket URL to connect to.

A device needs one URL and there is only one it can sensibly want, so most configurations should not have to write it out. Everything here has a default:

  #{}                                     wss://devices.nervescloud.com/device-socket/websocket?vsn=2.0.0
  #{host => "nh.example.com"}             wss://nh.example.com/device-socket/websocket?vsn=2.0.0
  #{url => "ws://192.168.1.10:4000"}      ws://192.168.1.10:4000/device-socket/websocket?vsn=2.0.0

Anything already there is kept, so a URL written out in full is passed through untouched and an unusual mount point survives.

Which path

NervesHub serves the device socket at two paths and which one to use depends on how the device authenticates.

A device with a client certificate connects to the device endpoint, where the socket is at /socket. A device with a shared secret goes through the web endpoint instead, where /socket is already taken by the browser socket and the device socket is at /device-socket.

Neither path implies an authentication method by itself -- the server reads the certificate if the connection presents one and the headers otherwise -- so this only picks the path the matching endpoint is listening on.

Function Index

default_host/0
resolve/1Build the URL an agent config asks for.

Function Details

default_host/0

default_host() -> binary()

resolve/1

resolve(Config::map()) -> {ok, binary()} | {error, term()}

Build the URL an agent config asks for.


Generated by EDoc