<commit_before>/**
 * Entry point of hyperion server
 * @module server/server
 */
'use strict';

var bodyParser = require('body-parser');
var express = require('express');
var mongoose = require('mongoose');
var path = require('path');

var log = require('lib/logger')(__filename);
var routes = require('routes/routes');
var sequences = require('models/sequences');

var app = express();
var exports = module.exports = app;

exports._expressListenCallback = (port, err) => {
  if (err) {
    return log.error({
      err: err
    }, '_expressListenCallback error');
  }
  log.trace('_expressListenCallback success PORT: '+
            port);
};

/**
 */
exports._initializeMongoose = (connectionUrl) => {
  //new Promise()
  mongoose.connect(connectionUrl); //TODO: Add logic to block until connection completes
};

/**
 *
 */
exports._initializeMiddleware = (app) => {
  app.use(bodyParser.json());
  app.use('/static', express.static(path.join(__dirname, '../client/build/')));
  app.use((req, res, next) => {
    // initialize middleware shared data namespace
    req.runnableData = {};
    next();
  });
};

/**
 * Initialize application.
 *   - Initialize sequences
 *   - Bind routes
 *   - Start express server
 */
exports.start = (opts) => {
  //new Promise()
  sequences.initialize(opts.sequences);
  exports._initializeMongoose(opts.db);
  exports._initializeMiddleware(app);
  routes.initialize(app);
  exports.listen(opts.port, exports._expressListenCallback.bind(this, opts.port));
};<commit_msg>Change route base from /static to /build for static files<commit_after>/**
 * Entry point of hyperion server
 * @module server/server
 */
'use strict';

var bodyParser = require('body-parser');
var express = require('express');
var mongoose = require('mongoose');
var path = require('path');

var clientRoutes = require('routes/client');
var log = require('lib/logger')(__filename);
var routes = require('routes/routes');
var sequences = require('models/sequences');

var app = express();
var exports = module.exports = app;

exports._expressListenCallback = (port, err) => {
  if (err) {
    return log.error({
      err: err
    }, '_expressListenCallback error');
  }
  log.trace('_expressListenCallback success PORT: '+
            port);
};

/**
 */
exports._initializeMongoose = (connectionUrl) => {
  //new Promise()
  mongoose.connect(connectionUrl); //TODO: Add logic to block until connection completes
};

/**
 *
 */
exports._initializeMiddleware = (app) => {
  app.use(bodyParser.json());
  app.use('/build', express.static(path.join(__dirname, '../client/build/')));
  app.use((req, res, next) => {
    // initialize middleware shared data namespace
    req.runnableData = {};
    next();
  });
};

/**
 * Initialize application.
 *   - Initialize sequences
 *   - Bind routes
 *   - Start express server
 */
exports.start = (opts) => {
  //new Promise()
  sequences.initialize(opts.sequences);
  exports._initializeMongoose(opts.db);
  exports._initializeMiddleware(app);
  routes.initialize(app);
  clientRoutes.initialize(app);
  exports.listen(opts.port, exports._expressListenCallback.bind(this, opts.port));
};
{'fraction_non_alphanumeric': 0.16347992351816443, 'fraction_numerical': 0.0, 'mean_word_length': 4.006379585326954, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '2708435', 'n_tokens_mistral': 924, 'n_tokens_neox': 934, 'n_words': 217}