<commit_before><commit_msg>node server to proxy github auths, prevents exposing client secrets<commit_after>var http = require('http');
var https = require('https');

function getToken(code, res) {
  if (typeof code != 'string') {
    res.writeHead(400, 'Must supply code');
    res.end();
    return;
  }

  var ghreq = https.request({
    hostname:'github.com',
    path:'/login/oauth/access_token',
    method:'POST',
    headers:{
      "Content-Type":"application/json",
      "Accept":"application/json"
    }
  }, function(ghres){
    var data = '';

    if (ghres.statusCode === 404) {
      res.writeHead(500);
      res.end();
      return;
    }

    ghres.on('data', function(chunk){data += chunk;});
    ghres.on('end', function() {
      var body = JSON.parse(data);
      if (body['error'] != null) {
        res.writeHead(400, body['error']);
        res.end();
        return;
      }

      res.writeHead(200);
      res.write(JSON.stringify(body));
      res.end();
    });
  });

  var data = {
    client_id:'7e75915ed424adcab18a',
    client_secret:'7c15acf6686b5c574cad071967919bb2a17ef39a',
    code:code
  };

  ghreq.write(JSON.stringify(data));
  ghreq.end();
}

http.createServer(function (req, res) {
  res.setHeader('Allow', 'POST');
  res.setHeader('Accept', 'application/json');
  var data = '';

  if (req.method !== 'POST') {
    res.writeHead(405);
    res.end();
    return;
  }

  var lcHeaders = {};
  for (k in req.headers)
    lcHeaders[k.toLowerCase()] = req.headers[k];

  if (lcHeaders['content-type'] !== 'application/json') {
    res.writeHead(415, 'Content-Type must be application/json');
    res.end();
    return;
  }

  //TODO: check req accept header

  req.on('data', function(chunk) {data += chunk;});
  req.on('end', function(){
    var body = data != '' ? JSON.parse(data) : undefined;
    getToken(body['code'], res);
  });
}).listen(80);

console.log('running on port 80');
{'fraction_non_alphanumeric': 0.1844559585492228, 'fraction_numerical': 0.031606217616580314, 'mean_word_length': 3.0911016949152543, 'pattern_counts': {'":': 2, '<': 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': '453016', 'n_tokens_mistral': 709, 'n_tokens_neox': 655, 'n_words': 127}