ExpressGateway / express-gateway

A microservices API Gateway built on top of Express.js
https://www.express-gateway.io
Apache License 2.0
2.98k stars 348 forks source link

req.params inside policy are not filled with API Endpoint path parts #519

Closed DrMegavolt closed 7 years ago

DrMegavolt commented 7 years ago
apiEndpoints:
  api:
    host: localhost
    paths: '/:id'

Expected req.params.id to be filled for requests like /45 It doesn't happened

Notes: So this is the part where pipeline is linked with API Endpoint https://github.com/ExpressGateway/express-gateway/blob/master/lib/gateway/pipelines.js#L100 and this is how a pipeline is created from configuration https://github.com/ExpressGateway/express-gateway/blob/master/lib/gateway/pipelines.js#L142 so pipeline is yet another router that is used as a handler It looks like fix will be just add mergeParams options into line 142

jakubgs commented 7 years ago

So I'm trying to understand this change and I was reading this: http://expressjs.com/en/4x/api.html#express.router

Preserve the req.params values from the parent router. If the parent and the child have conflicting param names, the child’s value take precedence.

I'm not sure how this applies to the configuration in apiEndpoints. What I'm getting from this is that every section inside of pipelines has it's own express.Router() object, right? https://github.com/musement/express-gateway/blob/master/lib/gateway/pipelines.js#L52 Looking at this line it seems like it does. What is the "parent router" in this case?

lkonzen-garupa commented 6 years ago

Any new about this?

XVincentX commented 6 years ago

@lkonzen-garupa This issue has been closed in November. Do you have cases where it's not working?

lkonzen-garupa commented 6 years ago

@XVincentX, thank you for the realy fast reply. Yes, I'm using the example plugin to implement a POC. On the example-policy I'm triing to get the params from the request, a POST request.

module.exports = {
  name: 'example',
  policy: actionParams => {
    return (req, res, next, data) => {
        req.params... /// nothing here

But the req object don't have any param data, not even a param object.

XVincentX commented 6 years ago

Can you share your entire gateway.config file and also show me how you're calling this specific endpoint?

We can also switch to our Gitter channel for a faster iteration.

lkonzen-garupa commented 6 years ago

gateway.config.yml

http:
  port: 8080
admin:
  port: 9876
  hostname: localhost
apiEndpoints:
  api:
    host: localhost
serviceEndpoints:
  garupadev:
    url: https://my-app-name.herokuapp.com/api/
policies:
  - cors
  - expression
  - log
  - proxy
  - rate-limit
  - example
pipelines:
  - name: default
    apiEndpoints:
      - api
    policies:
      - example:
          - action: 'apiKey' #just for test, not being use
      - proxy:
          - action:
              serviceEndpoint: garupadev
              changeOrigin: true`

The endpoint are called from a angular app, with POST to http://localhost:8080/login and sending a request payload with the folowing object:

{
    "email":"my-email@company.co",
    "password":"123123"
}

@XVincentX that paylod is what I are not getting.