<commit_before>require('../shared/globals');

var _ = require('underscore')
  , express = require('express')
  , Router = require('./router')
  , RestAdapter = require('./data_adapter/rest_adapter')
  , ViewEngine = require('./viewEngine')
  , middleware = require('./middleware');

module.exports = Server;

var defaultOptions = {
  dataAdapter: null,
  dataAdapterConfig: null,
  viewEngine: null,
  errorHandler: null,
  notFoundHandler: null,
  stashError: null,
  apiPath: '/api',
  appData: {},
  paths: {},
  viewsPath: null,
  defaultEngine: 'js'
};


function Server(options) {
  this.options = options || {};
  _.defaults(this.options, defaultOptions);

  this.expressApp = express();

  this.dataAdapter = this.options.dataAdapter || new RestAdapter(this.options.dataAdapterConfig);;

  this.viewEngine = this.options.viewEngine || new ViewEngine();

  this.errorHandler = this.options.errorHandler =
    this.options.errorHandler || express.errorHandler();

  this.router = new Router(this.options);

  /**
   * Tell Express to use our ViewEngine to handle .js, .coffee files.
   * This can always be overridden in your app.
   */
  this.expressApp.set('views', this.options.viewsPath || (process.cwd() + '/app/views'));
  this.expressApp.set('view engine', this.options.defaultEngine);
  this.expressApp.engine('js',     this.viewEngine.render);
  this.expressApp.engine('coffee', this.viewEngine.render);

  this._configured = false;

  /**
  * This is the middleware handler used to mount the Rendr server onto an Express app.
  */<commit_msg>Updated pull request based on good ideas expressed by dominikkrejcik in https://github.com/airbnb/rendr/pull/95<commit_after>require('../shared/globals');

var _ = require('underscore')
  , express = require('express')
  , Router = require('./router')
  , RestAdapter = require('./data_adapter/rest_adapter')
  , ViewEngine = require('./viewEngine')
  , middleware = require('./middleware');

module.exports = Server;

var defaultOptions = {
  dataAdapter: null,
  dataAdapterConfig: null,
  viewEngine: null,
  errorHandler: null,
  notFoundHandler: null,
  stashError: null,
  apiPath: '/api',
  appData: {},
  paths: {},
  viewsPath: null,
  defaultEngine: 'js'
};


function Server(options) {
  this.options = options || {};
  _.defaults(this.options, defaultOptions);

  this.expressApp = express();

  this.dataAdapter = this.options.dataAdapter || new RestAdapter(this.options.dataAdapterConfig);;

  this.viewEngine = this.options.viewEngine || new ViewEngine();

  this.errorHandler = this.options.errorHandler =
    this.options.errorHandler || express.errorHandler();

  this.router = new Router(this.options);

  /**
   * Tell Express to use our ViewEngine to handle .js, .coffee files.
   * This can always be overridden in your app.
   */
  this.expressApp.set('views', this.options.viewsPath || (process.cwd() + '/app/views'));
  this.expressApp.set('view engine', this.options.defaultEngine);
  this.expressApp.engine(this.options.defaultEngine, this.viewEngine.render);

  this._configured = false;

  /**
  * This is the middleware handler used to mount the Rendr server onto an Express app.
  */
{'fraction_non_alphanumeric': 0.1437578814627995, 'fraction_numerical': 0.0006305170239596469, 'mean_word_length': 4.1260096930533114, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '4776807', 'n_tokens_mistral': 977, 'n_tokens_neox': 949, 'n_words': 223}