具有快速网关的微服务:路由 return 404 错误
Microservices with express gateway : routes return 404 error
我的微服务是 运行 在端口 3000
中,我正在尝试通过 express-js gateway
代理请求
但是我在微服务中访问路由时遇到了问题
微服务路线
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
returns cannot get route error
.
访问我的微服务路由时
我会选择 Janus - https://hellofresh.gitbooks.io/janus/ API Gateway Management,因为它专门专注于此。看看,让我知道你的想法。
总的来说,请务必查看我们的 Path Management Piece。这将帮助您了解转发给您的服务的路径是什么。
具体谈谈你的问题——如果你想转发一个可以"continue"超出规范的路径,你需要将路径定义从/test
更改为/test*
。这指示网关路径不完整,可能会提供其他内容。
此外,在服务方面,我会将 app.use
更改为 app.get
,这样您就可以只听您感兴趣的动词。
干杯!
我的微服务是 运行 在端口 3000
中,我正在尝试通过 express-js gateway
但是我在微服务中访问路由时遇到了问题
微服务路线
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
returns cannot get route error
.
我会选择 Janus - https://hellofresh.gitbooks.io/janus/ API Gateway Management,因为它专门专注于此。看看,让我知道你的想法。
总的来说,请务必查看我们的 Path Management Piece。这将帮助您了解转发给您的服务的路径是什么。
具体谈谈你的问题——如果你想转发一个可以"continue"超出规范的路径,你需要将路径定义从/test
更改为/test*
。这指示网关路径不完整,可能会提供其他内容。
此外,在服务方面,我会将 app.use
更改为 app.get
,这样您就可以只听您感兴趣的动词。
干杯!