<commit_before>/**
 * Author: <NAME>
 * Date: 4/6/14
 *
 * Tracking middleware
 */
module.exports = function (Q, config, trackingService, log) {
    return {
        init: function init(ctx) {
            var isWebserver = ctx.container === 'webserver';
            var isApi = ctx.container === 'api';

            if (isWebserver) {
                ctx.server.ext('onPreAuth', function (req, reply) {
                    if (req.query.fromurl && req.session) {
                        req.yar.set('lastPage', req.query.fromurl);
                    }

                    reply.continue();
                });
            }

            ctx.server.ext('onPostHandler', function (req, reply) {
                var url = req.url.pathname;
                var domain = req.app.domain;
                var isNotStaticFile = url.indexOf(config.staticFiles.assets) < 0;

                if (isWebserver && domain !== 'trust' && url !== '/ping' && url !== '/robots.txt' && isNotStaticFile && req.yar) {
                    req.yar.set('lastPage', req.info.host + url);
                }
                else if (isApi) {
                    trackingService.trackApiCall({
                        caller:     req.caller,
                        host:       req.info.host,
                        method:     req.method,
                        url:        url
                    })
                        .catch(function (err) {
                            log.error(err);
                        });
                }

                reply.continue();
            });

            return new Q(ctx);
        }
    };
};<commit_msg>Final fix for getting lastPage to work with fromurl<commit_after>/**
 * Author: <NAME>
 * Date: 4/6/14
 *
 * Tracking middleware
 */
module.exports = function (Q, config, trackingService, log) {
    return {
        init: function init(ctx) {
            var isWebserver = ctx.container === 'webserver';
            var isApi = ctx.container === 'api';

            if (isWebserver) {
                ctx.server.ext('onPreAuth', function (req, reply) {
                    if (req.query.fromurl && req.yar) {
                        req.yar.set('lastPage', req.query.fromurl);
                    }

                    reply.continue();
                });
            }

            ctx.server.ext('onPostHandler', function (req, reply) {
                var url = req.url.pathname;
                var domain = req.app.domain;
                var isNotStaticFile = url.indexOf('/dist') !== 0 &&
                    config.staticFiles.assets.indexOf(req.info.host) < 0;

                if (isWebserver && domain !== 'trust' && url !== '/ping' && url !== '/robots.txt' && isNotStaticFile && req.yar) {
                    req.yar.set('lastPage', req.info.host + url);
                }
                else if (isApi) {
                    trackingService.trackApiCall({
                        caller:     req.caller,
                        host:       req.info.host,
                        method:     req.method,
                        url:        url
                    })
                        .catch(function (err) {
                            log.error(err);
                        });
                }

                reply.continue();
            });

            return new Q(ctx);
        }
    };
};
{'fraction_non_alphanumeric': 0.1255966587112172, 'fraction_numerical': 0.0032816229116945108, 'mean_word_length': 1.086496577473553, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6580464', 'n_tokens_mistral': 900, 'n_tokens_neox': 840, 'n_words': 176}