首页 > 解决方案 > 我无法在 Express-Gateway 上访问我想要的数据

问题描述

干得好伙计们。

我使用 Node JS 开发的项目在 8001 PORT 运行

http://localhost:8001/companies_getAll (return data)

我将使用 EXPRESS-GATEWAY,因为我想安装微服务构建。但是,虽然我进行了以下设置,但数据并没有返回给我。

http://localhost:8080/user (return "404 Not Found!")
http://localhost:8080/user/companies_getAll (return "Cannot GET /user/companies_getAll")

在Node JS方面,我有这样的命令。

const expressEndpoints = require('./endpoints/main')
expressApplication.use(expressEndpoints)

expressApplication.use((req, res) => {
    res.status(200).send('404 Not Found!')
})

expressApplication.listen(8001, () => {
    console.log('---------------------------------')
    console.log('Running User Service, PORT: 8001')
    console.log('---------------------------------')
})

最后我有了这样一个 YAML 文件。

http:
  port: 8080
admin:
  port: 9876
  host: localhost
apiEndpoints:
  api:
    host: localhost
    paths: '/user'
serviceEndpoints:
  user:
    url: 'http://localhost:8001'
policies:
  - basic-auth
  - cors
  - expression
  - key-auth
  - log
  - oauth2
  - proxy
  - rate-limit
  - rewrite
pipelines:
  default:
    apiEndpoints:
      - api
    policies:
      - proxy:
          - action:
              serviceEndpoint: user
              changeOrigin: true

我无法访问“companies_getAll”。你能帮我解决这个问题吗?

标签: javascriptnode.jsexpressexpress-gateway

解决方案


apiEndpoints 部分,路径使用完全匹配;您需要完整指定它:

paths: '/users/companies_getAll'

或使用通配符:

paths: '/users/*'

或者有一个路径数组

paths:
- '/user'
- '/user/companies_getAll'

    

推荐阅读