我的微服务正在端口 3000
中运行,我正在尝试通过 express-js 网关
代理请求
但是我在访问微服务中的路由时遇到问题
微服务路线
app.use('/sample',(req,res)=>{
res.json({
message:'Run with microservice'
})
})
我可以访问此路由http://localhost:3000/sample
。
这是我的gateway.config.yml
。
http:
port: 3004
admin:
port: 9876
hostname: localhost
apiEndpoints:
test:
host: localhost
paths: '/test'
serviceEndpoints:
test:
url: 'http://localhost:3002/'
policies:
- basic-auth
- cors
- expression
- key-auth
- log
- oauth2
- proxy
- rate-limit
pipelines:
test:
apiEndpoints:
- test
policies:
- proxy:
- action:
serviceEndpoint: test
changeOrigin: true
当我尝试通过 http://localhost:3004/test/sample
访问我的微服务路由时,返回无法获取路由错误
。
最佳答案
一般来说,请务必查看我们的 Path Management Piece 。这将帮助您了解转发到您的服务的路径是什么。
具体讨论您的问题 - 如果您想转发可以“继续”超出规范的路径,您需要将路径定义从 /test
更改为 /test*
。这指示网关路径不完整,可能会提供其他内容。
此外,在服务方面,我会将 app.use
更改为 app.get
,以便您只监听您感兴趣的动词。
干杯!
关于node.js - 具有快速网关的微服务 : routes return 404 error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52256252/