<commit_before>// the http server.
// Runs in the cluster worker processes.
//
// This is the only module that should create any
// long-lived things that might keep the event loop
// open indefinitely.  When the server closes, they
// should all be closed so that we can do a normal
// exit.

var cluster = require("cluster")
if (cluster.isMaster) {
  throw new Error("should only be invoked as cluster worker")
}

var config = require("./config.js")
, http = require("http")
, https = require("https")
, site = require("./site.js")
, server
, RedSess = require('redsess')
, bunyan = require('bunyan')

config.log.worker = cluster.worker.uniqueID
var logger = bunyan.createLogger(config.log)

console.error = logger.info.bind(logger)
console.log = logger.info.bind(logger)

RedSess.createClient(config.redis)

var httpServer = null
if (config.https) {
  server = https.createServer(config.https, site)
  if (config.httpPort) {
    var url = require('url')
    // redirect to the appropriate
    httpServer = http.createServer(function (req, res) {
      if (!req.headers.host) {
        res.writeHead(400)
        return res.end('No host header.')
      }
      var u = url.parse('https://' + req.headers.host + req.url)
      u.host = null
      u.href = null
      u.port = (config.port === 443) ? null : config.port
      u = url.format(u)
      res.writeHead(301, { location: u })
      res.end('moved: ' + u)
    })
    httpServer.listen(config.httpPort)
  }
} else {
  server = http.createServer(site)
}

server.listen(config.port, function () {
  logger.info("Listening on %d", config.port)
})

server.on('close', function () {
  // usually the cluster disconnect will close this one, too.
  try { httpServer.close() } catch (e) {}
  RedSess.close()<commit_msg>Add admin couch, and general-purpose redis client<commit_after>// the http server.
// Runs in the cluster worker processes.
//
// This is the only module that should create any
// long-lived things that might keep the event loop
// open indefinitely.  When the server closes, they
// should all be closed so that we can do a normal
// exit.

var cluster = require("cluster")
if (cluster.isMaster) {
  throw new Error("should only be invoked as cluster worker")
}

var config = require("./config.js")
, http = require("http")
, https = require("https")
, site = require("./site.js")
, server
, RedSess = require('redsess')
, bunyan = require('bunyan')

config.log.worker = cluster.worker.uniqueID
var logger = bunyan.createLogger(config.log)

console.error = logger.info.bind(logger)
console.log = logger.info.bind(logger)

// if there's an admin couchdb user, then set that up now.
if (config.couchAuth) {
  var ca = config.couchAuth.split(':')
  , name = ca.shift()
  , password = ca.join(':')
  , auth = { name: name, password: password }
  , CouchLogin = require('couch-login')
  config.adminCouch = new CouchLogin(config.registryCouch)
  config.adminCouch.login(auth, function (er, cr, data) {
    if (er) throw er
  })
}

RedSess.createClient(config.redis)

// a general purpose redis thing.
// Note: for sessions, use req.session, not this!
var r = config.redis
, redis = require('redis')
config.redis.client = redis.createClient(r.port, r.host, r)
if (r.auth) config.redis.client.auth(r.auth)

var httpServer = null
if (config.https) {
  server = https.createServer(config.https, site)
  if (config.httpPort) {
    var url = require('url')
    // redirect to the appropriate
    httpServer = http.createServer(function (req, res) {
      if (!req.headers.host) {
        res.writeHead(400)
        return res.end('No host header.')
      }
      var u = url.parse('https://' + req.headers.host + req.url)
      delete u.host
      u.port = (config.port === 443) ? null : config.port
      u = url.format(u)
      res.writeHead(301, { location: u })
      res.end('moved: ' + u)
    })
    httpServer.listen(config.httpPort)
  }
} else {
  server = http.createServer(site)
}

server.listen(config.port, function () {
  logger.info("Listening on %d", config.port)
})

server.on('close', function () {
  // usually the cluster disconnect will close this one, too.
  try { httpServer.close() } catch (e) {}
  RedSess.close()
  config.redis.client.quit()
{'fraction_non_alphanumeric': 0.14485207100591715, 'fraction_numerical': 0.004260355029585799, 'mean_word_length': 3.299084435401831, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '4276103', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1364, 'n_words': 385}