<commit_before>#import('dart:io');
#import('dart:json');

main() {
  HttpServer app = new HttpServer();

  app.addRequestHandler(
    (req) => req.method == 'GET' && req.path == '/',
    (req, res) {
      var file = new File('public/index.html');
      var stream = file.openInputStream();
      stream.pipe(res.outputStream);
    }
  );

  app.addRequestHandler(
    (req) => req.method == 'GET' && req.path == '/json',
    (req, res) {
      var data = {
        'title': 'Watchmen',
        'author': '<NAME>'
      };

      res.contentLength = JSON.stringify(data).length;
      res.headers.contentType = 'application/json';
      res.outputStream.writeString(JSON.stringify(data));
      res.outputStream.close();
    }
  );


  app.listen('127.0.0.1', 8000);
}<commit_msg>Public directory in app.dart<commit_after>#import('dart:io');
#import('dart:json');

main() {
  HttpServer app = new HttpServer();

  app.addRequestHandler(
    (req) {
      if (req.method != 'GET') return false;

      String path = publicPath(req.path);
      if (path == null) return false;

      req.session().data = {'path': path};
      return true;
    },
    (req, res) {
      var file = new File(req.session().data['path']);
      var stream = file.openInputStream();
      stream.pipe(res.outputStream);
    }
  );

  app.addRequestHandler(
    (req) => req.method == 'GET' && req.path == '/json',
    (req, res) {
      var data = {
        'title': 'Watchmen',
        'author': '<NAME>'
      };

      res.contentLength = JSON.stringify(data).length;
      res.headers.contentType = 'application/json';
      res.outputStream.writeString(JSON.stringify(data));
      res.outputStream.close();
    }
  );


  app.listen('127.0.0.1', 8000);
}

String publicPath(String path) {
  if (pathExists("public$path")) return "public$path";
  if (pathExists("public$path/index.html")) return "public$path/index.html";
}

boolean pathExists(String path) => new File(path).existsSync();
{'fraction_non_alphanumeric': 0.1847715736040609, 'fraction_numerical': 0.01015228426395939, 'mean_word_length': 2.9107142857142856, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5761585', 'n_tokens_mistral': 665, 'n_tokens_neox': 639, 'n_words': 122}