{"size": 930, "ext": "js", "max_stars_repo_path": "index.js", "max_stars_repo_name": "TobiasNickel/tAsyncExpress", "max_stars_repo_stars_event_min_datetime": "2018-05-11T05:43:24.000Z", "max_stars_repo_stars_event_max_datetime": "2018-05-11T05:43:24.000Z", "max_issues_repo_path": "index.js", "max_issues_repo_name": "TobiasNickel/tAsyncExpress", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "index.js", "max_forks_repo_name": "TobiasNickel/tAsyncExpress", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 35.7692307692, "max_line_length": 125, "alphanum_fraction": 0.4483870968}
/**
 * this module monkey patches the express/router/layer to allow async handlers
 */

require('express/lib/router/layer').prototype.handle_request = function handle(req, res, next) {
    var fn = this.handle;
    if (fn.length > 3) { return next(); }
    try {
        var promise = fn(req, res, next);
        if (typeof (promise) === 'object' && typeof (promise.catch) === 'function' && typeof (promise.then) === 'function') {
            promise.then((data) => {
                try {
                    if (data !== undefined){
                        if(typeof(data) == 'string' || Buffer.isBuffer(data)){
                            res.send(data);
                        } else {
                            res.json(data);
                        }
                    } 
                } catch (err) {/*ignore error*/ }
            });
            promise.catch(next);
        }
    } catch (err) { next(err); }
}; 
