Accessing config in middleware plugin


#1

Hi,

I built a middleware POST plugin that accesses the session data and also makes a request using ‘TykMakeHttpRequest’.

The newRequest I have for the http request looks something like this.
newRequest = {
“Method”: “GET”,
“Body”: “”,
“headers”: {},
“Domain”: “http://www.domain.net”,
“Resource”: “/somendpoint/” + atok,
“FormData”: {}
};

One thing I am trying to do is configure “Domain”: “http://www.domain.net”. That is, use some sort of Environment variable or a config file to get the url instead of hardcoding it since it is going to be different for different environments. As in, url could be http://www.domain.net on non-production environment and http://www.somedomain.com on a production environment.

Is there a way to access some kind of config, whether it is in a file or environment variables, through the middleware JS ?


Using Tyk to combine multiple API calls
#2

Afraid not - the sandbox is pretty hermetic.

You could have a local service running that provides env data and do an HTTP request to it in the middleware.


#3

Thanks for the reply. :slightly_smiling: