ExpressGateway / express-gateway

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

[Question] Conditioning a proxy to a header property #987

Closed samuelkitazume closed 4 years ago

samuelkitazume commented 4 years ago

I've been trying to use express-gateway as a gateway for two (or more) versions of the frontend. We are studying if express-gateway could be an option to migrate smoothly our frontend versions, so we intend to have conditions a little more hidden in order to determine which API (Frontend server in our case) will retrieve the docs/information the client is asking (so we can have the same route retrieving different resources depending on some hidden condition, like headers or cookies).

Here lies my problem, I've seen you guys exposed of conditions and an expression condition for more customized kind of condition, but, as express already say in their docs, they don't expose headers on req object anymore, instead they created a function you can call for a property in the header object.

What I mean:

condition:
      name: expression 
      expression: "req.header.my_prop='my value'" OR
      expression: "req.cookies.my_prop='my value'"

So, I'm trying to understand if there's an alternative for that or is there something I'm missing in the documentation.

(I know retrieving static resources is not the purpose of the project, but we were trying to see if this could be an option)

samuelkitazume commented 4 years ago

I spent 2h trying this and now actually the req.get is working... it was giving me an error of "invalid left-side statement" something like this...

Now it seems to work... o0