【问题标题】:Override express-gateway config覆盖 express-gateway 配置
【发布时间】:2020-04-11 10:45:39
【问题描述】:

我正在为 Amazon ECS 容器部署一个快速网关,我试图找出在 gateway.config.yml 覆盖 serviceEndpoint 部分的最佳方法,因为服务 URL 明显不同。

我需要改变这个

serviceEndpoints:
  user:
    url: 'http://localhost:3001'
  auth:
    url: 'http://localhost:3004'
  customer:
    url: 'http://localhost:3002'

对此:

serviceEndpoints:
  user:
    url: 'http://user.service:3001'
  auth:
    url: 'http://auth.service:3004'
  customer:
    url: 'http://customer.sevice:3002'

等等。

我认为我可以维护 2 个配置文件副本并在 Docker 构建中交换它们,但我认为这不是最好的选择,我认为实现服务发现将是另一种选择。

有什么想法吗?

TIA!

【问题讨论】:

    标签: node.js amazon-ecs express-gateway


    【解决方案1】:

    我找到了解决方案,配置现在使用 ENVIRONMENT 变量为:

    服务端点: 用户: 网址:'http://${USER_SERVICE:-localhost}:${USER_SERVICE_PORT:-3001}' 授权: 网址:'http://${AUTH_SERVICE:-localhost}:${AUTH_SERVICE_PORT:-3004}' 顾客: 网址:'http://${CUSTIMER_SERVICE:-localhost}:${CUTOMER_SERVICE_PORT:-3002}'

    一切正常。

    问候。

    【讨论】:

    • 我不知道为什么,但我必须使用 dotenv 进行 express-gateway 才能看到我的 .env 变量。 import dotenv from 'dotenv';dotenv.config();
    猜你喜欢
    • 2021-05-22
    • 2011-09-24
    • 2017-09-08
    • 2014-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-12
    • 2012-05-08
    相关资源
    最近更新 更多