diff --git a/apisix/http/router/radixtree_host_uri.lua b/apisix/http/router/radixtree_host_uri.lua index 25dec6589fb9..e45f1a08e458 100644 --- a/apisix/http/router/radixtree_host_uri.lua +++ b/apisix/http/router/radixtree_host_uri.lua @@ -17,6 +17,9 @@ local require = require local router = require("resty.radixtree") local core = require("apisix.core") +local plugin = require("apisix.plugin") +local service_fetch = require("apisix.http.service").get + local ipairs = ipairs local type = type local error = error @@ -52,6 +55,12 @@ local function push_host_router(route, host_routes, only_uri_routes) end local hosts = route.value.hosts or {route.value.host} + if #hosts == 0 and route.value.service_id then + local service = service_fetch(route.value.service_id) + if service.value.hosts ~= nil then + hosts = service.value.hosts + end + end local radixtree_route = { paths = route.value.uris or route.value.uri, diff --git a/apisix/schema_def.lua b/apisix/schema_def.lua index 0f50db2e1b9c..be01189fe876 100644 --- a/apisix/schema_def.lua +++ b/apisix/schema_def.lua @@ -498,6 +498,11 @@ _M.service = { type = "object", properties = { id = id_schema, + hosts = { + type = "array", + items = host_def, + uniqueItems = true, + }, plugins = plugins_schema, upstream = upstream_schema, upstream_id = id_schema,