heimdall v0.6.8 Heimdall.DynamicRoutes

Module for dynamically registering routes and routing requests.

This is where most of the magic happens. All traffic through the application is routed through this plug.

Routes are stored in an ETS table to be looked up when the plug is called. When called Heimdall.DynamicRoutes search for a route that matches the request, wrap all plugs in the route into one function and call it with the current request. The final plug in the chain will always be Heimdall.Plug.ForwardRequest

Summary

Functions

Call is responsible for the majority of the logic in heimdall

Returns the route in registered routes that matches a path as a list (which is how plug conns reperesent them internally). Will return nil if no routes are found

Registers a route for later lookup

Unregisters a route given its host and path

Unregisters all routes for a give table

Functions

call(conn, tab)

Call is responsible for the majority of the logic in heimdall.

It looks up the incoming request using Heimdall.DynamicRoutes.lookup_path/3. If the path matches it either strips the matched path and moves it into the script_name property of the Conn or leaves it as be. Finally it wraps all the filter plugs, starting with the plugs in specified in the :filter_before_all app config, and ending with the Heimdall.Plug.ForwardRequest plug.

init(list)
lookup_path(tab, host, conn_path)

Returns the route in registered routes that matches a path as a list (which is how plug conns reperesent them internally). Will return nil if no routes are found.

Examples

iex> Heimdall.DynamicRoutes.register(:some_table, "localhost", ["test", "path"], [], [])
true
iex> Heimdall.DynamicRoutes.lookup_path(:some_table, "localhost", ["test", "path"])
{"localhost", ["test", "path"], [], [], true, []}

iex> Heimdall.DynamicRoutes.register(:some_table, "localhost", ["test", "path"], [], [])
true
iex> Heimdall.DynamicRoutes.lookup_path(:some_table, "localhost", ["test", "path", "but", "longer"])
{"localhost", ["test", "path"], [], [], true, []}
new(table_name)
register(tab, route)

Registers a route for later lookup

register(tab, host, path, plugs, opts, strip_path \\ true, proxy_path \\ [])

Registers a route for later lookup

unregister(tab, host, path)

Unregisters a route given its host and path

unregister_all(tab)

Unregisters all routes for a give table