defmodule ReverseProxy.Router do @moduledoc """ This Plug routes our requests from a set of servers in the config file. It does that by reading the whole config file and reading the hosts and their upstreams. """ use Plug.Router plug :match plug :dispatch for {host, upstream} <- Application.get_env(:rexy, :upstreams, []) do @upstream upstream match _, host: host do ReverseProxy.Service.call(conn, upstream: @upstream) end end #TODO: Maybe add a nice static page to be rendered instead. match _, do: conn |> send_resp(400, "Bad Request") end