<commit_before>#!/usr/bin/env node

var minimist = require('minimist')
var WebSocketServer = require('ws').Server
var freeport = require('freeport')
var request = require('request')
var websocket = require('websocket-stream')
var docker = require('docker-browser-console')
var root = require('root')
var url = require('url')
var send = require('send')
var path = require('path')
var pump = require('pump')

var argv = minimist(process.argv, {
  alias: {port:'p', host:'h', docker:'d', help:'h'},
  default: {port:process.env.PORT || 8080},
  booleans: {persist:true}
})

if (argv.help) {
  console.log('Usage: node server.js [options]')
  console.log()
  console.log('  --port,    -p  [8080]          (port to listen on)')
  console.log('  --docker,  -d  [$DOCKER_HOST]  (optional host of the docker daemon)')
  console.log('  --persist                      (persist /root in the containers)')
  console.log('')
  return
}

var DOCKER_HOST = argv.docker || (process.env.DOCKER_HOST || '127.0.0.1').replace(/^.+:\/\//, '').replace(/:\d+$/, '').replace(/^\/.+$/, '127.0.0.1')

var server = root()
var wss = new WebSocketServer({server:server})
var containers = {}

wss.on('connection', function(connection) {
  var url = connection.upgradeReq.url.slice(1)
  var persist = argv.persist && !!url
  var id = url || Math.random().toString(36).slice(2)
  var subdomain = id+'.c.'+connection.upgradeReq.headers.host
  var stream = websocket(connection)

  freeport(function(err, filesPort) {
    if (err) return connection.destroy()
    freeport(function(err, httpPort) {
      if (err) return connection.destroy()

      var container = containers[id] = {
        id: id,
        host: 'http://'+subdomain,
        ports: {http:httpPort, fs:filesPort}
      }

      console.log('Spawning new container (%s)', id)

      var opts = {
        env: {
          CONTAINER_ID: container.id,
          HOST: container.host,
          PORT: 80
        },
        ports: {
          80: httpPort,
          8441: filesPort<commit_msg>change persistance option<commit_after>#!/usr/bin/env node

var minimist = require('minimist')
var WebSocketServer = require('ws').Server
var freeport = require('freeport')
var request = require('request')
var websocket = require('websocket-stream')
var docker = require('docker-browser-console')
var root = require('root')
var url = require('url')
var send = require('send')
var path = require('path')
var pump = require('pump')

var argv = minimist(process.argv, {
  alias: {port:'p', host:'h', docker:'d', help:'h'},
  default: {port:process.env.PORT || 8080}
})

if (argv.help) {
  console.log('Usage: node server.js [options]')
  console.log()
  console.log('  --port,    -p  [8080]          (port to listen on)')
  console.log('  --docker,  -d  [$DOCKER_HOST]  (optional host of the docker daemon)')
  console.log('  --allow-persist                (allow persistance of /root in the containers)')
  console.log('')
  return
}

var DOCKER_HOST = argv.docker || (process.env.DOCKER_HOST || '127.0.0.1').replace(/^.+:\/\//, '').replace(/:\d+$/, '').replace(/^\/.+$/, '127.0.0.1')

var server = root()
var wss = new WebSocketServer({server:server})
var containers = {}

wss.on('connection', function(connection) {
  var url = connection.upgradeReq.url.slice(1)
  var persist = argv['allow-persist'] && !!url
  var id = url || Math.random().toString(36).slice(2)
  var subdomain = id+'.c.'+connection.upgradeReq.headers.host
  var stream = websocket(connection)

  freeport(function(err, filesPort) {
    if (err) return connection.destroy()
    freeport(function(err, httpPort) {
      if (err) return connection.destroy()

      var container = containers[id] = {
        id: id,
        host: 'http://'+subdomain,
        ports: {http:httpPort, fs:filesPort}
      }

      console.log('Spawning new container (%s)', id)

      var opts = {
        env: {
          CONTAINER_ID: container.id,
          HOST: container.host,
          PORT: 80
        },
        ports: {
          80: httpPort,
          8441: filesPort
{'fraction_non_alphanumeric': 0.17350469599604548, 'fraction_numerical': 0.015818091942659415, 'mean_word_length': 3.121181262729124, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '4567687', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1320, 'n_words': 319}