'use strict';

var path = require('path');
var fs = require('fs');
var ejs = require('ejs');

ejs.filters.toBool = function(v) {
  return v ? 'on' : 'off';
};

var rawTemplate = fs.readFileSync(
  path.join(__dirname, 'config_template.ejs'),
  { encoding: 'utf8' }
);
var compiledTemplate = ejs.compile(rawTemplate, {open: '{{', close: '}}'});

/*eslint-disable complexity */
exports.generate = function(config) {
  config.directoryIndex = config.directoryIndex || false;
  config.gzip = config.gzip || false;
  config.ssi = config.ssi || false;
  config.tls = config.tls || config.spdy || false;
  config.spdy = config.spdy || false;

  normalizeProxy(config);

  return compiledTemplate(config);
};
/*eslint-enable */

function normalizeProxy(config) {
  if (typeof config.proxy === 'string') {
    config.proxy = {
      '/': config.proxy
    };
  } else if (typeof config.proxy !== 'object') {
    config.proxy = {};
  }
}

'use strict';

var path = require('path');
var fs = require('fs');
var ejs = require('ejs');

ejs.filters.toBool = function(v) {
  return v ? 'on' : 'off';
};

var rawTemplate = fs.readFileSync(
  path.join(__dirname, 'config_template.ejs'),
  { encoding: 'utf8' }
);
var compiledTemplate = ejs.compile(rawTemplate, {open: '{{', close: '}}'});

/*eslint-disable complexity */
exports.generate = function(config) {
  config.directoryIndex = config.directoryIndex || false;
  config.gzip = config.gzip || false;
  config.ssi = config.ssi || false;
  config.tls = config.tls || config.spdy || false;
  config.spdy = config.spdy || false;

  normalizeProxy(config);

  return compiledTemplate(config);
};
/*eslint-enable */

function normalizeProxy(config) {
  config.proxy = config.proxy || {};
  if (typeof config.proxy === 'string') {
    config.proxy = {
      '/': config.proxy
    };
  }
}

Fix proxy section fallback