<commit_before>/* server.js: run this with Node.js in the publish/ folder to start your server.
 * Copyright © 2011 <NAME>, <NAME>. All rights reserved.
 * The following code is covered by the GPLv2 license. */

// Please look for documentation in `./Server.md`


// SERVER CONFIGURATION
//

// Location of the root. If this is "/root", the fake root
// will be at "http://example.com/root/".
var ROOT_PREFIX = '/root';

// Import modules
var camp = require ('./camp/camp'),
    arbor = require ('./lib/fs'),
    sync = require ('./lib/sync'),
    prof = require ('./lib/profiler'),
    nodepath = require ('path');


sync.main();

prof.main();

// FILE-SYSTEM ACCESS
//

// Redirection of `http://<DNS>.tld/root/something`
// to look for `/root/something`.
camp.handle (new RegExp(ROOT_PREFIX + '/(.*)'), function (query, path) {

  // Default plug
  path[0] = '/pencil.html';

  // Template data
  var data = {path:path[1]};

  // TODO: in the future, this will be the #plug system.
  // If they want a directory, load gateway.
  ///console.log('SERVER:ROOT: what is %s?', path[1]);
  arbor.getfile (path[1], function (err, file) {
    if (err) {
      console.error(err);
      data.error = err.message;
      path[0] = '/404.html';
      camp.server.emit ('fsplugged', data);
      return;
    }
    if (file.isOfType('text/plain')) {
      path[0] = '/pencil.html';
      data.dirname = file.name;  // This will become the title.
      var mime = arbor.type.nameFromType(file.type);
      data.mime = mime;
      var util = require('util');
      camp.server.emit ('fsplugged', data);

    } else if (file.isOfType('dir')) {
      path[0] = '/gateway.html';
      data.nav = path[1].split('/').filter(function(e){return e.length > 0;});
      data.dirname = file.name || 'The File Tree';
      file.content (function (err, content) {
        if (err)  console.error(err);
        data.filenames = [];
        for (var file in content) {
          if (content[file].isOfType('dir'))  file += '/';
          data.filenames.push(file);
        }
        ///console.log('SERVER:ROOT: data sent from dir is', data);
        camp.server.emit('fsplugged', data);
      });
    }
  });

}, function fsplugged(data) {
  return data;
});


var root = arbor.root;<commit_msg>[Server] Partial fix for missing /<commit_after>/* server.js: run this with Node.js in the publish/ folder to start your server.
 * Copyright © 2011 <NAME>, <NAME>. All rights reserved.
 * The following code is covered by the GPLv2 license. */

// Please look for documentation in `./Server.md`


// SERVER CONFIGURATION
//

// Location of the root. If this is "/root", the fake root
// will be at "http://example.com/root/".
var ROOT_PREFIX = '/root';

// Import modules
var camp = require ('./camp/camp'),
    arbor = require ('./lib/fs'),
    sync = require ('./lib/sync'),
    prof = require ('./lib/profiler'),
    nodepath = require ('path');


sync.main();

prof.main();

// FILE-SYSTEM ACCESS
//

// Redirection of `http://<DNS>.tld/root/something`
// to look for `/root/something`.
camp.handle (new RegExp(ROOT_PREFIX + '/(.*)'), function (query, path) {

  // Default plug
  path[0] = '/pencil.html';

  // Template data
  var data = {path:path[1]};

  // TODO: in the future, this will be the #plug system.
  // If they want a directory, load gateway.
  ///console.log('SERVER:ROOT: what is %s?', path[1]);
  arbor.getfile (path[1], function (err, file) {
    if (err) {
      console.error(err);
      data.error = err.message;
      path[0] = '/404.html';
      camp.server.emit ('fsplugged', data);
      return;
    }
    if (file.isOfType('text/plain')) {
      path[0] = '/pencil.html';
      data.dirname = file.name;  // This will become the title.
      var mime = arbor.type.nameFromType(file.type);
      data.mime = mime;
      var util = require('util');
      camp.server.emit ('fsplugged', data);

    } else if (file.isOfType('dir')) {
      path[0] = '/gateway.html';
      // FIXME when viewing https://thefiletree.com/dir1/dir2, links go from
      //       dir1 instead of dir2 (because of the missing /)
      if ( path[1][path[1].length-1] !== '/' ) {
        path[1] += '/';
        data.path += '/';
      }
      data.nav = path[1].split('/').filter(function(e){return e.length > 0;});
      data.dirname = file.name || 'The File Tree';
      file.content (function (err, content) {
        if (err)  console.error(err);
        data.filenames = [];
        for (var file in content) {
          if (content[file].isOfType('dir'))  file += '/';
          data.filenames.push(file);
        }
        ///console.log('SERVER:ROOT: data sent from dir is', data);
        camp.server.emit('fsplugged', data);
      });
    }
  });

}, function fsplugged(data) {
  return data;
});


var root = arbor.root;
{'fraction_non_alphanumeric': 0.1797752808988764, 'fraction_numerical': 0.008739076154806492, 'mean_word_length': 2.480811006517017, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 1, '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': '6215399', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1583, 'n_words': 439}