<commit_before>const https = require('https');
const lb = require('../serverLb/library/nodelb');
const fs = require('fs');
// const lb = require('nodelb');
const statsController = require('../controllers/statsController');

const options = [];
for (let i = 2; i < process.argv.length; i += 2) {
  options.push({
    hostname: process.argv[i],
    port: process.argv[i + 1],
    active: true,
  });
}

const secureOpts = {
    key: fs.readFileSync('server-key.pem'),
    cert: fs.readFileSync('server-crt.pem'),
    ca: fs.readFileSync('ca-crt.pem'),
};

const rp = lb.deploy('rp', options, () => statsController.createSession(options));
rp.setRoutes([['GET', '/']]); // ['GET', '/html']
rp.healthCheck(10000);
rp.on('cacheRes', () => statsController.countRequests('Cached Response'));
rp.on('targetRes', () => statsController.countRequests(options[0].hostname.concat(':').concat(options[0].port)));

const server = https.createServer(secureOpts, (bReq, bRes) => {
  if (bReq.method === 'GET' && bReq.url === '/stats') return statsController.getServerStats(bReq, bRes);
  rp.init(bReq, bRes);
}).listen(1337);
console.log('Server running at 127.0.0.1:1337');<commit_msg>left some comments for testing self-signed certificates<commit_after>const https = require('https');
const lb = require('../serverLb/library/nodelb');
const fs = require('fs');
// const lb = require('nodelb');
const statsController = require('../controllers/statsController');

const options = [];
for (let i = 2; i < process.argv.length; i += 2) {
  options.push({
    hostname: process.argv[i],
    port: process.argv[i + 1],
    active: true,
  });
}

const secureOpts = {
    key: fs.readFileSync('server-key.pem'),
    cert: fs.readFileSync('server-crt.pem'),
    ca: fs.readFileSync('ca-crt.pem'),
};
// ONLY uncomment below for testing https with a self-signed certificate
// process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
const rp = lb.deploy('rp', options, () => statsController.createSession(options));
rp.setRoutes([['GET', '/']]); // ['GET', '/html']
rp.healthCheck(10000);
rp.on('cacheRes', () => statsController.countRequests('Cached Response'));
rp.on('targetRes', () => statsController.countRequests(options[0].hostname.concat(':').concat(options[0].port)));

const server = https.createServer(secureOpts, (bReq, bRes) => {
  if (bReq.method === 'GET' && bReq.url === '/stats') return statsController.getServerStats(bReq, bRes);
  rp.init(bReq, bRes);
}).listen(1337);
console.log('Server running at 127.0.0.1:1337');
{'fraction_non_alphanumeric': 0.20615261685976827, 'fraction_numerical': 0.019576508190171794, 'mean_word_length': 4.976133651551312, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '5981455', 'n_tokens_mistral': 869, 'n_tokens_neox': 845, 'n_words': 167}