【发布时间】:2019-04-26 07:05:20
【问题描述】:
我在访问另一个容器中的一个容器路由时遇到了问题。例如,我有两个名为 user-service 和 api-gateway 的微服务。我正在尝试访问 api-gateway 中的 user-service 路由。
我的 api-gateway 文件可能如下所示
const userServiceProxy = httpProxy(http://localhost:8093);
this.app.post('/admin/register', async(req, res) => {
userServiceProxy(req, res);
});
api-gateway 正在端口 8080
上运行我的 user-service 文件可能如下所示
app.post('/admin/register', function (req, res) {
res.send('POST request')
})
当我使用端口 8080 通过 api-gateway 访问路由时,我无法调用该路由,但是当我尝试使用端口 8093 访问时,我可以看到结果。
我的 docker-compose 文件可能如下所示
version: '3'
services:
api-gateway:
container_name: api-gateway
build: './api-gateway'
ports:
- "8080:8080"
links:
- user-service
user-service:
build: ./user-service
container_name: user-service
ports:
- "8093:8093"
任何帮助将不胜感激,在此先感谢!
【问题讨论】:
-
httpProxy对象是什么? -
当用户尝试使用端口 8080 访问路由时,通常会重定向到运行在端口 上的 用户服务 的路由8093。顺便说一句,我使用 express-http-proxy