我有多个微服务可供客户端通过Ocelot
网关访问。在配置文件中,有一些属性可以指定下游主机和端口。这必须为每条路线完成。
问题是,如果服务的主机名或端口发生变化,我将不得不修改与该特定服务关联的每条路由。
所以,问题是,是否可以在ocelot.json
配置文件中引入 ENV 变量?在这种情况下,我只需要修改一个 ENV 变量,所有相关的路由都会受到影响。
这是我当前的配置文件(我正在使用docker-compose
服务名称作为主机):
"Routes": [
{
"UpstreamPathTemplate": "/api/v1/signIn",
"DownstreamPathTemplate": "/api/v1/signIn",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "identity-api",
"Port": 80
}
],
"SwaggerKey": "Identity"
},
{
"UpstreamPathTemplate": "/api/v1/validate",
"DownstreamPathTemplate": "/api/v1/validate",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "identity-api",
"Port": 80
}
],
"SwaggerKey": "Identity"
},
我想要的是:
"Routes": [
{
"UpstreamPathTemplate": "/api/v1/signIn",
"DownstreamPathTemplate": "/api/v1/signIn",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": {SERVICE_HOST},
"Port": {SERVICE_PORT}
}
],
"SwaggerKey": "Identity"
},
{
"UpstreamPathTemplate": "/api/v1/validate",
"DownstreamPathTemplate": "/api/v1/validate",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": {SERVICE_HOST},
"Port": {SERVICE_PORT}
}
],
"SwaggerKey": "Identity"
},