TreeGateway / tree-gateway

This is a full featured and free API Gateway
http://treegateway.com
MIT License
189 stars 42 forks source link

cache fails first time while storing #178

Open diptiranjan-das opened 5 years ago

diptiranjan-das commented 5 years ago

While calling for the first time to an api, it showing network error but still it saving in cache. For next time it fetching from cache and working. Dynamic injected code in file -> node_modules\tree-gateway\dist\pipeline\cache\server-cache.js

ServerCache.cacheStore.get(req.originalUrl, function(err, entry){ if (err) { return next();

}
if (entry) {
    res.contentType(entry.mimeType || "text/html");
    res.send(new Buffer(entry.content, "base64"));
}
else {
    req.parseRespBody = true;
    var send = res.send.bind(res);
    res.send = function (body) {
        var ret = send(body);
        if ( !body ) {
            body = '';
        }
        body = new Buffer(body).toString("base64");
        if ( typeof body !== "string" ) {
            return ret;
        }
        if ((res.statusCode >= 200 && res.statusCode < 300) || (res.statusCode === 304)){
            ServerCache.cacheStore.set(req.originalUrl, {content: body,mimeType: this._headers["content-type"]}, 10000);
        }
        return ret;
    };
    return next();
}

}); return;