diff --git a/lib/uplink/clients/caddy/config/builder.ex b/lib/uplink/clients/caddy/config/builder.ex index e1cf75e..3e0b9e7 100644 --- a/lib/uplink/clients/caddy/config/builder.ex +++ b/lib/uplink/clients/caddy/config/builder.ex @@ -129,6 +129,13 @@ defmodule Uplink.Clients.Caddy.Config.Builder do ) do main_routing = Map.get(metadata.main_port, :routing) + main_routing_hosts = + if main_routing do + main_routing.hosts + else + [] + end + main_paths = if main_routing do main_routing.paths @@ -187,11 +194,16 @@ defmodule Uplink.Clients.Caddy.Config.Builder do } end) + main_hosts = + metadata.hosts + |> Enum.concat(main_routing_hosts) + |> Enum.uniq() + main_route = %{ group: main_group, match: [ %{ - host: metadata.hosts, + host: main_hosts, path: main_paths } ], @@ -233,6 +245,20 @@ defmodule Uplink.Clients.Caddy.Config.Builder do routing = Map.get(port, :routing) + routing_hosts = + if routing do + Enum.map(routing.hosts, fn host -> + port.slug <> "." <> host + end) + else + [] + end + + hosts = + hosts + |> Enum.concat(routing_hosts) + |> Enum.uniq() + paths = if routing do routing.paths diff --git a/lib/uplink/packages/metadata/port.ex b/lib/uplink/packages/metadata/port.ex index 02743ae..b0ba68b 100644 --- a/lib/uplink/packages/metadata/port.ex +++ b/lib/uplink/packages/metadata/port.ex @@ -10,6 +10,7 @@ defmodule Uplink.Packages.Metadata.Port do embeds_one :routing, Routing, primary_key: false do field :router_id, :integer + field :hosts, {:array, :string}, default: [] field :paths, {:array, :string}, default: ["*"] end end @@ -23,7 +24,7 @@ defmodule Uplink.Packages.Metadata.Port do defp routing_changeset(routing, params) do routing - |> cast(params, [:router_id, :paths]) + |> cast(params, [:router_id, :hosts, :paths]) |> validate_required([:router_id, :paths]) end end