javascript - 我无法在 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”。你能帮我解决这个问题吗?
解决方案
在apiEndpoints 部分,路径使用完全匹配;您需要完整指定它:
paths: '/users/companies_getAll'
或使用通配符:
paths: '/users/*'
或者有一个路径数组
paths:
- '/user'
- '/user/companies_getAll'
推荐阅读
- javascript - 尝试分配给 React Native 组件中的只读属性
- python - How to extract color features via histogram from a masked image?
- python - scipy优化中的自定义收敛标准
- java - 检查我的世界服务器是否启用了白名单
- list - Understanding function with <|> operator
- java - 如何将json转换为地图
确保整数将是整数 - css - b-list-group 和 b-list-group-item 的 BootstrapVue 样式
- python - 没有获得多处理 netmiko 多个设备的输出
- mysql - Can't connect to a DB: database is closed
- python - Python SkLearn: ValueError: Found input variables with inconsistent numbers samples: [1173, 294]