<commit_before>/**
 * Module dependencies.
 */

var async = require('async')
var config = require('lib/config')
var app = require('lib/boot')
var serverFactory = require('lib/server-factory')
var notifier = require('democracyos-notifier')
var notifications = require('lib/notifications').notifier
var log = require('debug')('democracyos:server')

module.exports = function listen (opts, callback) {
  var servers = serverFactory(app, opts)

  if (notifications.embedded()) {
    // Start web servers alongside the notifications server
    async.parallel([
      startWebServer,
      startNotificationsService
    ], callback)
  } else {
    // Just start the regular web server
    startWebServer(callback)
  }

  function startWebServer (cb) {
    servers.forEach(function (s) {
      s.listen(function (err) {
        log('Server started at port %s.', s.port)

        cb && cb(err)
      })
    })
  }

  function startNotificationsService (cb) {
    var opts = {
      mongoUrl: config.mongoUrl,
      organizationName: config.notifications.mailer.name,
      organizationEmail: config.notifications.mailer.email,
      mailer: config.notifications.mailer
    }

    log('About to start embedded notifier notifier with options: %j', opts)
    notifier(opts, function (err) {
      if (err) return log('Unexpected error while starting embedded notifications service')

      log('Embedded notifications service started')

      if (cb) cb(err)
    })
  }
}<commit_msg>add availableLocales on embedded notifier config<commit_after>/**
 * Module dependencies.
 */

var async = require('async')
var config = require('lib/config')
var app = require('lib/boot')
var serverFactory = require('lib/server-factory')
var notifier = require('democracyos-notifier')
var notifications = require('lib/notifications').notifier
var log = require('debug')('democracyos:server')

module.exports = function listen (opts, callback) {
  callback = callback || noop

  var servers = serverFactory(app, opts)

  if (notifications.embedded()) {
    // Start web servers alongside the notifications server
    async.parallel([
      startWebServer,
      startNotificationsService
    ], callback)
  } else {
    // Just start the regular web server
    startWebServer(callback)
  }

  function startWebServer (cb) {
    servers.forEach(function (s) {
      s.listen(function (err) {
        log('Server started at port %s.', s.port)

        cb(err)
      })
    })
  }

  function startNotificationsService (cb) {
    var opts = {
      mongoUrl: config.mongoUrl,
      organizationName: config.notifications.mailer.name,
      organizationEmail: config.notifications.mailer.email,
      mailer: config.notifications.mailer,
      defaultLocale: config.locale,
      availableLocales: config.availableLocales
    }

    log('Starting embedded notifier...')
    notifier(opts, function (err) {
      if (err) {
        log('Unexpected error while starting embedded notifier', err)
        return cb(err)
      }

      log('Embedded notifier started.')

      cb()
    })
  }
}

function noop () {}
{'fraction_non_alphanumeric': 0.11598440545808966, 'fraction_numerical': 0.0, 'mean_word_length': 3.288300835654596, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6496497', 'n_tokens_mistral': 890, 'n_tokens_neox': 860, 'n_words': 228}