node.js - 具有快速网关的微服务 : routes return 404 error

标签 node.js express microservices express-gateway

我的微服务正在端口 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/

相关文章:

node.js - 用于聊天应用程序的nodejs的memcache vs redis

c++ - 不支持 NodeJS 插件 Unordered_map?

node.js - Nginx 根据用户登录提供不同的文件?

mysql - 如何在mysql中保存和检索图像?

node.js - TypeError : Cannot read property 'csrfSecret' of undefined at Object. 句柄 - 使用 Node.js

node.js - Chai 测试复杂对象

javascript - 如何使用 request.query 获取变量

python - docker 中的微服务 FastAPI 测试,返回 404

java - 创建可从 Android 应用程序调用的 NodeJS 微服务

java - 将redis订阅消息转换为模型对象以进行调用