Hybrid gateway JSVM middleware, 'config_data' not available?

We have a JSVM function that works find in the on-prem docker quickstart stack, such as:

myPlugin.NewProcessRequest(function(request, session, config) {

		log("----> Running myPlugin JSVM Middleware");
		log("config = " + JSON.stringify(config));
		log("request = " + JSON.stringify(request));
		log("session = " + JSON.stringify(session));

When running in hybrid however (despite the API def having a valid “config_data” json blob defined)

2017-08-17T20:31:32.047042863Z time="Aug 17 20:31:32" level=info msg="config = undefined" type=log-msg

1 Like

Hi,

Are you running the latest gateway container with 2.3.8?

This works for me:

Code:

var helloWorld = new TykJS.TykMiddleware.NewMiddleware({});
log("------------ Initialising PRE middleware ------------");
helloWorld.NewProcessRequest(function(request, session, config) {
    // You can log to Tyk console output by calloing the built-in log() function:
    log("Running sample  PRE PROCESSOR JSVM middleware with iteration")
    for (var i in config.config_data) {
        log(i)
        log(config.config_data[i])
    }
    // You MUST return both the request and session metadata    
    return helloWorld.ReturnData(request, {});
});

// Ensure init with a post-declaration log message
log("------------ Sample PRE middleware initialised ------------");

Output:

[Aug 17 21:32:11]  INFO jsvm-logmsg: a type=log-msg
[Aug 17 21:32:11]  INFO jsvm-logmsg: b type=log-msg
[Aug 17 21:32:11]  INFO jsvm-logmsg: x type=log-msg
[Aug 17 21:32:11]  INFO jsvm-logmsg: y type=log-msg```

yes, using the tykio/tyk-hybrid-docker image

2017-08-17T20:30:29.821615528Z time=“Aug 17 20:30:29” level=info msg=“Gateway started (v2.3.8)”

Weird… trying to see what else this could be

How are you loading the plugins? The test above was by using the mounted folder method:

middleware/{api-id}/pre/{funcName}.js

The gateway is configured w/ coprocess on, and a bundle url. The API def references a bundle zip file, that is successfully being pulled and installed locally on the gateway, and invoked… just that config_data seems undefined.

So in the container it lives at:

/opt/tyk/middleware/bundles/dceede4c43c34e7652d565d6f04bdf58-my-bundle.zip/function.js

I’ve tried deleting the config_data in the admin.cloud.tyk.io dashboard, and re-creating it, to no avail. The API when invoked on the gateway is definitely invoking the function, but that config variable is undefined.

That is quite odd, can you try with the middleware folder method mentioned above?

It’s documented here

cc @matiasb for help on the why the bundle method may not be getting config data.

@Martin @matiasb

Tried the middleware folder method as well (no bundle) and same thing. The config object is just “undefined”

There was an issue in our hybrid container which we have now resolved.

Confirmed fixed, thanks

FYI @Martin, doing a custom image against the hybrid 2.3.8 image, still shows this issue, only “latest” has the fix. Something may be messed up w/ your image signatures on dockerhub fyi

tykio/tyk-hybrid-docker                latest              ea51e5d9f951        2 weeks ago         1.52GB
tykio/tyk-hybrid-docker                v2.3.8              8167a33514e3        3 weeks ago         1.52GB

Thanks for the heads up, I’ll let the team now.