My microservice is running in port 3000
and I am trying to proxy the request via express-js gateway
But I got a problem with accessing routes in microservice
MICRO SERVICE ROUTE
app.use('/sample',(req,res)=>{
res.json({
message:'Run with microservice'
})
})
And I am able to access this route http://localhost:3000/sample
.
Here is my 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
When I try to access my microservice route via http://localhost:3004/test/sample
returns cannot get route error
.
in general, make sure to review our Path Management Piece . This will help you understand what's the PATH that gets forwarded to your service.
Talking specifically about your question — if you want to forward a path that can "continue" beyond the specification, you need to change the path definition from /test
to /test*
. This instructs the gateway that the path is not complete and something else might be provided.
Also, on the service side, I'd change the app.use
to app.get
so you're listening only for the VERBS you're interested.
Cheers!
You have to make a get in you express-microservice.
Something like this.
app.get('/test',(req,res)=>{
res.json({
message:'Run with microservice'
})
})
I would go with Janus - https://hellofresh.gitbooks.io/janus/ for API Gateway Management as it specializes specifically on that. Have a look and let me know what you think.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.