问题描述
干得好。
我用 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")
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('---------------------------------')
})
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 section中,路径使用精确匹配;您需要完整地指定它:
paths: '/users/companies_getAll'
或者使用通配符:
paths: '/users/*'
或者有一组路径
paths:
- '/user'
- '/user/companies_getAll'