<commit_before>var express = require('express');
var app = module.exports = express();
var configure = require('./config/env');
var mongoose = require('mongoose');
var Primus = require('primus');
var Comment = require('./models/comment');

configure(app);

var server = require('http').createServer(app);
var primus = new Primus(server, {transformer: 'websockets'});

primus.use('rooms', require('primus-rooms'));
primus.use('hostname', require('./modules/primus-hostname'));
primus.on('connection', function(spark) {
  console.log('connected', spark.id, '@domain', spark.hostname);
  spark.join(spark.hostname);
});

primus.on('disconnection', function(spark) {
  console.log('disconnected', spark.id);
});

var ensureRequestComesFromRightDomain = function(req, res, next) {
  if (req.hostname === req.param('domain')) {
    return next();
  }
  if (req.hostname === '127.0.0.1') {
    return next();
  }
  res.send(403);
};

app.get('/', function(req, res) {
  res.send('Hello World');
});

app.get('/db', function(req, res) {
  res.send((mongoose.connection.readyState === 1) ? 200 : 503);
});
<commit_msg>Fix domain detection in domain check middleware<commit_after>var express = require('express');
var app = module.exports = express();
var configure = require('./config/env');
var mongoose = require('mongoose');
var Primus = require('primus');
var Comment = require('./models/comment');

configure(app);

var server = require('http').createServer(app);
var primus = new Primus(server, {transformer: 'websockets'});

primus.use('rooms', require('primus-rooms'));
primus.use('hostname', require('./modules/primus-hostname'));
primus.on('connection', function(spark) {
  console.log('connected', spark.id, '@domain', spark.hostname);
  spark.join(spark.hostname);
});

primus.on('disconnection', function(spark) {
  console.log('disconnected', spark.id);
});

var ensureRequestComesFromRightDomain = function(req, res, next) {
  var origin = req.hostname;
  if (req.headers.origin) {
    origin = require('url').parse(req.headers.origin).hostname;
  }
  if (origin === req.param('domain')) {
    return next();
  }
  if (req.hostname === '127.0.0.1') {
    return next();
  }
  res.send(403);
};

app.get('/', function(req, res) {
  res.send('Hello World');
});

app.get('/db', function(req, res) {
  res.send((mongoose.connection.readyState === 1) ? 200 : 503);
});

{'fraction_non_alphanumeric': 0.20413327709827078, 'fraction_numerical': 0.013496415014761703, 'mean_word_length': 5.177083333333333, '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': '174444', 'n_tokens_mistral': 787, 'n_tokens_neox': 775, 'n_words': 157}