<commit_before>'use strict';
const express = require('express');
const proxy   = require('http-proxy-middleware');
const gzip    = require('connect-gzip-static');
const morgan  = require('morgan');
const url     = require('url');
const util    = require('./util');

// dev/dist mode
if (process.argv.length !== 3 || ['dev', 'dist'].indexOf(process.argv[2]) < 0) {
  console.log('Usage: node server.js [dev|dist]');
  process.exit(1);
}
let isDist = process.argv[2] === 'dist';
util.buildIndex(isDist); // throw compilation errors right away

let app = express();
let env = util.readEnv(isDist);
let port = parseInt(process.env.PORT || 4300);
app.use(morgan('combined', {
  skip: req => req.path === '/' || !util.isIndex(req.path)
}));

// proxy feed requests
let xmlMimes = [
  'application/rss+xml',
  'application/rdf+xml;q=0.8',
  'application/atom+xml;q=0.6',
  'application/xml;q=0.4',
  'text/xml;q=0.4',
].join(',');
app.get('/proxy', (req, res, next) => {
  let parts = url.parse(req.query.url || '');
  if (parts.protocol && parts.host) {
    req.proxyUrl = `${parts.protocol}//${parts.host}${parts.path || ''}`;
    next();
  } else {
    console.error(`Proxy error: invalid url '${req.url}'`);
    res.status(400).send('Invalid proxy url');
  }
});
app.get('/proxy', proxy({
  target: 'http://dummy-proxy-host.prx.org',
  router: req => req.proxyUrl,
  onProxyReq: req => {
    req.setHeader('accept', xmlMimes);
    req.setHeader('user-agent', 'play.prx.org feed proxy');
  },<commit_msg>Don't double-send headers when following redirects<commit_after>'use strict';
const express = require('express');
const proxy   = require('http-proxy-middleware');
const gzip    = require('connect-gzip-static');
const morgan  = require('morgan');
const url     = require('url');
const util    = require('./util');

// dev/dist mode
if (process.argv.length !== 3 || ['dev', 'dist'].indexOf(process.argv[2]) < 0) {
  console.log('Usage: node server.js [dev|dist]');
  process.exit(1);
}
let isDist = process.argv[2] === 'dist';
util.buildIndex(isDist); // throw compilation errors right away

let app = express();
let env = util.readEnv(isDist);
let port = parseInt(process.env.PORT || 4300);
app.use(morgan('combined', {
  skip: req => req.path === '/' || !util.isIndex(req.path)
}));

// proxy feed requests
let xmlMimes = [
  'application/rss+xml',
  'application/rdf+xml;q=0.8',
  'application/atom+xml;q=0.6',
  'application/xml;q=0.4',
  'text/xml;q=0.4',
].join(',');
app.get('/proxy', (req, res, next) => {
  let parts = url.parse(req.query.url || '');
  if (parts.protocol && parts.host) {
    req.proxyUrl = `${parts.protocol}//${parts.host}${parts.path || ''}`;
    next();
  } else {
    console.error(`Proxy error: invalid url '${req.url}'`);
    res.status(400).send('Invalid proxy url');
  }
});
app.get('/proxy', proxy({
  target: 'http://dummy-proxy-host.prx.org',
  router: req => req.proxyUrl,
  headers: {
    'accept': xmlMimes,
    'user-agent': 'play.prx.org feed proxy',
  },
{'fraction_non_alphanumeric': 0.22022022022022023, 'fraction_numerical': 0.01334668001334668, 'mean_word_length': 4.072758037225042, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, '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': '2793286', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1065, 'n_words': 216}