<commit_before>'use strict';

var express = require('express');
var http = require('http');
var logger = require('morgan');
var Path = require('path');
var request = require('request');

exports.startServer = function startServer(port, path, callback) {
  var app = express();
  var server = http.createServer(app);

  app.use(express.static(Path.join(__dirname, path)));
  app.use(express.static(Path.join(__dirname, 'data')));
  app.use(logger('dev'));

  var apiUrl = 'http://169.254.94.120:4567/json/lastresults';
  // var apiUrl = 'http://localhost:4567/json/lastresults';
  app.use('/lastresults', function(req, res) {
    req.pipe(request(apiUrl)).pipe(res);
  });

  server.listen(port, callback);
};<commit_msg>feat server.js: handle proxy error by sending a 502<commit_after>'use strict';

var express = require('express');
var http = require('http');
var logger = require('morgan');
var Path = require('path');
var request = require('request');

exports.startServer = function startServer(port, path, callback) {
  var app = express();
  var server = http.createServer(app);

  app.use(express.static(Path.join(__dirname, path)));
  app.use(express.static(Path.join(__dirname, 'data')));
  app.use(logger('dev'));

  var apiUrl = 'http://169.254.94.120:4567/json/lastresults';
  // var apiUrl = 'http://localhost:4567/json/lastresults';
  app.use('/lastresults', function(req, res) {
    req.pipe(request(apiUrl, function(error, response, body){
      if (error.code === 'ECONNREFUSED') {
        res.status(502).send({ error: 'Connection refused: live results unavailable' });
      } else { 
        throw error; 
      }
    })).pipe(res);
  });

  server.listen(port, callback);
};
{'fraction_non_alphanumeric': 0.18337264150943397, 'fraction_numerical': 0.025943396226415096, 'mean_word_length': 4.545751633986928, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4275931', 'n_tokens_mistral': 568, 'n_tokens_neox': 531, 'n_words': 115}