<commit_before>"use strict";

const history = require("history");
const serverRender = require("./utils/serverRender.js");
const getDomainRoutes = require("./utils/getDomainRoutes.js");

const createLocation = history.createLocation;
const createMemoryHistory = history.createMemoryHistory;

function completeRender(cfg, routes) {
    if (routes) {
        cfg.routes = routes;
    }

    return serverRender(cfg);
}

function render(cfg) {
    return function serverHandoff(request, cookies, wildcatConfig) {
        const header = request.header;
        const url = request.url;

        const serverHistory = createMemoryHistory();
        const serverLocation = createLocation(url);

        cfg = Object.assign({}, cfg, {
            cookies,
            history: serverHistory,
            location: serverLocation,
            request,
            wildcatConfig
        });

        if (!cfg.routes && cfg.domains) {
            return new Promise((resolve) => {
                getDomainRoutes(cfg.domains, header, (error, routes) => {
                    if (error) {
                        return resolve({
                            error,
                            status: 500
                        });
                    }

                    return resolve(completeRender(cfg, routes));
                });
            });
        }

        return completeRender(cfg);
    };
}

module.exports = function server(cfg) {
    return render(cfg);
};<commit_msg>fix(react-wildcat-handoff): reject Promise if error is found<commit_after>"use strict";

const history = require("history");
const serverRender = require("./utils/serverRender.js");
const getDomainRoutes = require("./utils/getDomainRoutes.js");

const createLocation = history.createLocation;
const createMemoryHistory = history.createMemoryHistory;

function completeRender(cfg, routes) {
    if (routes) {
        cfg.routes = routes;
    }

    return serverRender(cfg);
}

function render(cfg) {
    return function serverHandoff(request, cookies, wildcatConfig) {
        const header = request.header;
        const url = request.url;

        const serverHistory = createMemoryHistory();
        const serverLocation = createLocation(url);

        cfg = Object.assign({}, cfg, {
            cookies,
            history: serverHistory,
            location: serverLocation,
            request,
            wildcatConfig
        });

        if (!cfg.routes && cfg.domains) {
            return new Promise((resolve, reject) => {
                getDomainRoutes(cfg.domains, header, (error, routes) => {
                    if (error) {
                        return reject(error);
                    }

                    return resolve(completeRender(cfg, routes));
                });
            });
        }

        return completeRender(cfg);
    };
}

module.exports = function server(cfg) {
    return render(cfg);
};
{'fraction_non_alphanumeric': 0.10757108598835217, 'fraction_numerical': 0.0010277492291880781, 'mean_word_length': 1.9614604462474645, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '360433', 'n_tokens_mistral': 737, 'n_tokens_neox': 711, 'n_words': 168}