<commit_before>/*
 *  Copyright 2011 Rackspace
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

var path = require('path');
var fs = require('fs');
var async = require('async');
var _ = require('underscore');

var express = require('express');

var load_devops = require('./load_devops');
var middleware = require('./middleware');
var routes = require('./routes');
var routes_secure = require('./routes_secure');
var utils = require('../utils');
var settings = require('../settings');
var pollers = require('./pollers');

var TEMPLATE_DIR = path.join(__dirname, 'views');
var status_api = new utils.api_cache();

exports.run = function(port, devops_directory, host) {
  var app, secure_app, certificate, privateKey;
  var base_path = path.join(__dirname, '../..');
  var apps = [];
  var devops;

  if(settings.private_key && settings.cert){
    try{
      privateKey = fs.readFileSync(path.join(base_path, settings.private_key)).toString();
      certificate = fs.readFileSync(path.join(settings.cert)).toString();
    }catch(e){
      console.warn('Could not find the private key and/or cert; not starting the API.');
    }
    if (settings.valid_users.length <= 0){
      console.warn('You must define valid_users in settings; not starting the API.');
    }else if(privateKey && certificate){
      secure_app = express.createServer({key: privateKey, cert: certificate});
      apps.push(secure_app);
    }
  }else{
    console.warn('No key/cert defined in settings; not starting the API.');
  }

  app = express.createServer();
  apps.push(app);
  _.each(apps, function(_app){
    _app.set('views', TEMPLATE_DIR);
    _app.set('view engine', 'jade');
    _app.set('view options', {layout: false});
    _app.use(middleware.logger());
    if (settings.testing === true){
      _app.enable('testing');
    }
  });

  app.use('/static', express.static(path.join(__dirname, '..', '..', 'extern')));
  app.use('/static', express.static(path.join(__dirname, '..', '..', 'static')));
  /* setup middleware */
  //app.use(middleware.cache_me(5*60));
  //app.use(middleware.devops_directory_setter(devops_directory));<commit_msg>Don't use base path.<commit_after>/*
 *  Copyright 2011 Rackspace
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

var path = require('path');
var fs = require('fs');
var async = require('async');
var _ = require('underscore');

var express = require('express');

var load_devops = require('./load_devops');
var middleware = require('./middleware');
var routes = require('./routes');
var routes_secure = require('./routes_secure');
var utils = require('../utils');
var settings = require('../settings');
var pollers = require('./pollers');

var TEMPLATE_DIR = path.join(__dirname, 'views');
var status_api = new utils.api_cache();

exports.run = function(port, devops_directory, host) {
  var app, secure_app, certificate, privateKey;
  var apps = [];
  var devops;

  if(settings.private_key && settings.cert){
    try{
      privateKey = fs.readFileSync(path.join(settings.private_key)).toString();
      certificate = fs.readFileSync(path.join(settings.cert)).toString();
    }catch(e){
      console.warn('Could not find the private key and/or cert; not starting the API.');
    }
    if (settings.valid_users.length <= 0){
      console.warn('You must define valid_users in settings; not starting the API.');
    }else if(privateKey && certificate){
      secure_app = express.createServer({key: privateKey, cert: certificate});
      apps.push(secure_app);
    }
  }else{
    console.warn('No key/cert defined in settings; not starting the API.');
  }

  app = express.createServer();
  apps.push(app);
  _.each(apps, function(_app){
    _app.set('views', TEMPLATE_DIR);
    _app.set('view engine', 'jade');
    _app.set('view options', {layout: false});
    _app.use(middleware.logger());
    if (settings.testing === true){
      _app.enable('testing');
    }
  });

  app.use('/static', express.static(path.join(__dirname, '..', '..', 'extern')));
  app.use('/static', express.static(path.join(__dirname, '..', '..', 'static')));
  /* setup middleware */
  //app.use(middleware.cache_me(5*60));
  //app.use(middleware.devops_directory_setter(devops_directory));
{'fraction_non_alphanumeric': 0.1548141086749285, 'fraction_numerical': 0.00457578646329838, 'mean_word_length': 3.9258215962441314, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '862753', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1570, 'n_words': 444}