Usir server for rondo applications
Rondo.Server is available in Hex and can be installed as:
- Add
rondo_serverto your list of dependencies inmix.exs:
defdepsdo[{:rondo_server,"~> 0.1.0"}]endStart by creating the rondo component we want to render:
defmoduleMyApp.HellodouseRondo.Componentdefrender(%{"name"=>name})doel("Text",nil,[name])endendNext define a handler.
defmoduleMyApp.HandlerdouseRondo.Server# The setup method is called for every connection.# The return value is the options to be fed to application initializationdefsetup(_opts,_protocol_info)do{:ok,%{}}end# Called per app. Returns the store and internal statedefinit(app_opts)do{:ok,Rondo.Test.Store.init(%{}),app_opts}end# Here we define how the usir paths route to rondo componentsdefroute("/"=_path,props,_state)do{:ok,el(MyApp.Hello,props)}enddefroute(_,_,_)do{:error,:not_found}end# This method handles authentication. In this example we won't set it up.defauthenticate(_method,_token,_state)do:errorendendNow we can create an acceptor from the handler and start a usir transport:
acceptor=Rondo.Server.acceptor(MyApp.Handler,%{})Usir.Transport.HTTP.Server.http(acceptor)Now mount the application at / with a usir client and we're in business.