<commit_before>//
// This is the Render Service main application
//

// HTTP connection
const http = require('http');
const querystring = require('querystring');

var port = process.env.PORT || 3000;
var host = process.env.HOST || 'localhost';

// Helper classes (which will eventually become separate services)
var gameService = require('./GameService');
var utils = require('./utils');

// Create the server
const server = http.createServer((req, res) => {  
  res.setHeader('Access-Control-Allow-Origin', '*'); 
  res.setHeader('Access-Control-Allow-Methods', "GET, PUT, POST, OPTIONS");
  res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");

  // We only support GET
  if (req.method == 'GET')
  {
      // The can pass in a GUID either as a querystring, or via cookie - querystring takes precendence
      var params = querystring.parse(req.url, "?");
      var action = params.action;
      var userID = params.userID;

      // Start by reading cookies to see if they have a GUID set (and we can play with state that way)
      if (!userID)
      {
          userID = ParseUserID(req, fullbody);
      }

      // Allow them to send flushcache in the URL to clear state
      if ((params["/flushcache"] === '') && userID)
      {
          // Delete this entry from the cache
          console.log("Flushing " + userID);
          gameService.RemoveKey(userID);
          userID = null;
      }
      else if ((params["/fullstate"] === '') && userID)
      {
          // Return the whole thing from Redis
          console.log("Copying " + userID);
          gameService.GetFullGame(userID, function(error, game) {
              res.setHeader('Content-Type', 'application/json');
              if (error) {
                  res.statusCode = 400;
                  res.end(JSON.stringify({error: error}))
              }
              else {
                  // OK, set the response
                  res.statusCode = 200;<commit_msg>Cleanup<commit_after>//
// This is the Render Service main application
//

// HTTP connection
const http = require('http');
const querystring = require('querystring');

var port = process.env.PORT || 3000;
var host = process.env.HOST || 'localhost';

// Helper classes (which will eventually become separate services)
var gameService = require('./GameService');
var utils = require('./utils');

// Create the server
const server = http.createServer((req, res) => {  
  res.setHeader('Access-Control-Allow-Origin', '*'); 
  res.setHeader('Access-Control-Allow-Methods', "GET, PUT, POST, OPTIONS");
  res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");

  // We only support GET
  if (req.method == 'GET')
  {
      // The can pass in a GUID either as a querystring, or via cookie - querystring takes precendence
      var params = querystring.parse(req.url, "?");
      var action = params.action;
      var userID = params.userID;

      // Start by reading cookies to see if they have a GUID set (and we can play with state that way)
      if (!userID)
      {
          userID = ParseUserID(req, fullbody);
      }

      // Allow them to send flushcache in the URL to clear state
      if (Object.prototype.hasOwnProperty.call(params, "/flushcache") && userID)
      {
          // Delete this entry from the cache
          console.log("Flushing " + userID);
          gameService.RemoveKey(userID);
          userID = null;
      }
      else if (Object.prototype.hasOwnProperty.call(params, "/fullstate") && userID)
      {
          // Return the whole thing from Redis
          console.log("Copying " + userID);
          gameService.GetFullGame(userID, function(error, game) {
              res.setHeader('Content-Type', 'application/json');
              if (error) {
                  res.statusCode = 400;
                  res.end(JSON.stringify({error: error}))
              }
              else {
                  // OK, set the response
                  res.statusCode = 200;
{'fraction_non_alphanumeric': 0.12760675273088382, 'fraction_numerical': 0.004965243296921549, 'mean_word_length': 2.3215169002473206, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2579531', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1106, 'n_words': 337}