<commit_before>require('newrelic');
const config = require('./config/config');
const express = require('express');
const helmet = require('helmet');
const compression = require('compression');
const cors = require('cors');
const path = require('path');
const app = express();

// we can make some nicer assumptions about security if query values are only
// ever strings, not arrays or objects
app.set('query parser', 'simple');

// Redirect to https in production
app.use((req, res, next) => {
  if (process.env.NODE_ENV === 'production') {
    if (req.hostname !== 'www.toiletmap.org.uk') {
      res.redirect(301, 'https://www.toiletmap.org.uk' + req.originalUrl);
    } else if (req.headers['x-forwarded-proto'] !== 'https') {
      res.redirect(301, 'https://' + req.hostname + req.originalUrl);
    } else {
      next();
    }
  } else {
    next();
  }
});

app.use(helmet());
app.use(compression());
app.use(cors());

// Add API routes
const routes = require('./routes');
app.use('/api', routes);

//redirect admin to explorer
app.all('/admin', (req, res) => res.redirect(301, '/explorer'));

// Serve the built explorer UI from /explorer
app.use('/explorer', express.static(path.join(__dirname, 'www-explorer')));
app.get('/explorer/*', function(req, res) {
  res.sendFile(path.join(__dirname, 'www-explorer', 'index.html'));
});

// Serve the built UI from the root
app.use(express.static(path.join(__dirname, 'www')));
app.get('/*', function(req, res) {
  res.sendFile(path.join(__dirname, 'www', 'index.html'));
});

// auto-init if this app is not being initialised by another module
if (!module.parent) {
  app.listen(config.app.port, () => {<commit_msg>fix: better redirect<commit_after>require('newrelic');
const config = require('./config/config');
const express = require('express');
const helmet = require('helmet');
const compression = require('compression');
const cors = require('cors');
const path = require('path');
const app = express();

// we can make some nicer assumptions about security if query values are only
// ever strings, not arrays or objects
app.set('query parser', 'simple');

// Redirect to https in production
app.use((req, res, next) => {
  if (process.env.NODE_ENV === 'production') {
    if (req.hostname !== 'www.toiletmap.org.uk') {
      res.redirect(301, 'https://www.toiletmap.org.uk' + req.originalUrl);
    } else if (req.headers['x-forwarded-proto'] !== 'https') {
      res.redirect(301, 'https://' + req.hostname + req.originalUrl);
    } else {
      next();
    }
  } else {
    next();
  }
});

app.use(helmet());
app.use(compression());
app.use(cors());

// Add API routes
const routes = require('./routes');
app.use('/api', routes);

//redirect admin to explorer
app.all('/admin', (req, res) => res.redirect(301, '/explorer/'));

// Serve the built explorer UI from /explorer
app.use('/explorer', express.static(path.join(__dirname, 'www-explorer')));
app.get('/explorer/*', function(req, res) {
  res.sendFile(path.join(__dirname, 'www-explorer', 'index.html'));
});

// Serve the built UI from the root
app.use(express.static(path.join(__dirname, 'www')));
app.get('/*', function(req, res) {
  res.sendFile(path.join(__dirname, 'www', 'index.html'));
});

// auto-init if this app is not being initialised by another module
if (!module.parent) {
  app.listen(config.app.port, () => {
{'fraction_non_alphanumeric': 0.19665271966527198, 'fraction_numerical': 0.005379557680812911, 'mean_word_length': 4.246081504702194, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 12, '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': '1174259', 'n_tokens_mistral': 1087, 'n_tokens_neox': 1070, 'n_words': 278}