Middleware gets purged after API reload

Hi Jess,

My question is, what is the recommended method to add middleware to an API in the CE?
In the docs it states that in the CE it needs to be done in the api definition file. However, there is no such file, since the API was created in the Dashboard. So, what do I do?

The link you posted earlier is for the PRO edition, which I do not have. If I try it, nothing happens. I even enabled debugging in the /etc/init.d/tyk-gateway` file to:

program=/opt/tyk-gateway/tyk
args='--conf=/opt/tyk-gateway/tyk.conf --debug'

But I can’t see any output whatsoever.

What I tried is to modify the API definition directly in the database, like so:

"custom_middleware" : {
        "pre" : [ 
            {
                "name" : "sampleMiddleware",
                "path" : "middleware/sampleMiddleware.js",
                "require_session" : false
            }, 
            {
                "name" : "tokenInjection",
                "path" : "middleware/tokenInjection.js",
                "require_session" : false
            }
        ],
        "post" : [],
        "post_key_auth" : [],
        "auth_check" : {
            "name" : "",
            "path" : "",
            "require_session" : false
        },

But is that even possible to do?