All files / lib config.js

93.1% Statements 27/29
83.33% Branches 10/12
100% Functions 0/0
93.1% Lines 27/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92              1x   1x 1x 1x                                                                 1x                           1x 1x 1x 1x   1x 1x   1x 1x 1x       1x 1x 1x       1x 1x 1x 1x   1x 1x 1x   1x 1x   1x  
"use strict";
/**
 * Configures `GlaceJS` proxy before run.
 *
 * @module
 */
 
var path = require("path");
 
var _ = require("lodash");
const expect = require("chai").expect;
var U = require("glace-utils");
 
/* Set up default config */
 
/**
 * Contains `GlaceJS` proxy configuration.
 * 
 * @namespace GlaceConfig
 * @prop {?string} [url=null] - Proxied URL.
 * @prop {object} cache - Cache config.
 * @prop {number} [cache.ttl] - Time to life cache. Default is maximum.
 * @prop {number} [cache.size] - Maximum cached file size. Default is 10 GB.
 * @prop {boolean} [cache.use=false] - Use cache.
 * @prop {boolean} [cache.existing=false] - Use existing cache if exists.
 * @prop {boolean} [cache.folder=cwd/.proxy-cache] - Cache folder.
 * @prop {object} chrome - Chrome config.
 * @prop {boolean} [chrome.launch=false] - Launch chrome browser.
 * @prop {boolean} [chrome.incognito=false] - Use incognito mode in chrome.
 * @prop {object} log - Log config.
 * @prop {string} [log.level=debug] - Log level.
 * @prop {string} [log.path=cwd/glace-proxy.log] - Log file path.
 * @prop {boolean} [log.stdout=false] - Print log messages to terminal.
 * @prop {object} proxy - Proxy config.
 * @prop {number} [proxy.timeout=60000] - Proxy time to wait for remote response, ms.
 * @prop {number} [proxy.http=false] - Launch http proxy.
 * @prop {number} [proxy.port=0] - Proxy port. By default will be assigned by OS.
 * @prop {boolean} [proxy.global=false] - Launch global proxy.
 * @prop {number} [proxy.globalPort=8888] - Global proxy port.
 * @prop {boolean} [proxy.installCertificates] - Install global proxy certificates
 *  as trusted. Windows only. Admin privileges are required.
 * @prop {number} [proxy.reconnect=2] - Number of reconnect attemptions if
 *  remote side breaks connection.
 */
var config = _.merge(U.config, {
    cache: {
        ttl: Number.MAX_SAFE_INTEGER,
        size: 10 * 1024 * 1024 * 1024
    },
    chrome: {
    },
    log: {
        level: "debug",
    },
    proxy: {
        timeout: 60000,
    },
});
var args = config.args;
config.report = U.defVal(config.report, {});
config.report.dir = U.defVal(config.report.dir, U.cwd);
config.cluster = U.defVal(config.cluster, {});
/* Use CLI arguments */
config.web = U.defVal(config.web, {});
config.web.url = args.webUrl;  // proxied URL
 
config.proxy.http = !!args.httpProxy;  // default is `false`
config.proxy.port = args.httpProxyPort || 0;  // default is random
Iif (config.cluster.slavesNum) {
    expect(config.proxy.port,
        "`--http-proxy-port` is incompatible with `--slaves`").to.be.equal(0);
}
config.proxy.global = !!args.globalProxy;  //default `false`
config.proxy.globalPort = args.globalProxyPort || 0;  // default is random
Iif (config.cluster.slavesNum) {
    expect(config.proxy.globalPort,
        "`--global-proxy-port` is incompatible with `--slaves`").to.be.equal(0);
}
config.proxy.speed = args.speed;  // default unlimited
config.proxy.installCertificate = !!args.installCertificate;  //default `false`
config.proxy.sslCaDir = path.resolve(config.report.dir, U.defVal(args.sslCaDir, ".certificates"));
config.proxy.reconnect = args.reconnect || 2;  // TODO maybe to make as CLI option
 
config.cache.use = !!args.cache || !!args.existingCache;  // default `false`
config.cache.existing = !!args.existingCache;  // default `false`
config.cache.folder = path.resolve(config.report.dir, U.defVal(args.cacheFolder, ".proxy-cache"));
 
config.chrome.launch = !!args.chrome;  // default `false`
config.chrome.incognito = !!args.chromeIncognito;  // default `false`
 
module.exports = config;