<commit_before>var fs = require('fs'),
    express = require('express'),
    request = require('request'),
    url = require('url'),
    lessMiddleware = require('less-middleware'),
    config = require('config'),
    mustache = require('mustache'),
    controllers = require('./app/controllers')

var app = express()

app.use(express.compress())
app.use(express.cookieParser())
app.use(express.cookieSession({ secret: 'seger handrail' }))

app.use(lessMiddleware({
  src: __dirname + '/public',
  compress: (process.env.NODE_ENV == 'production'),
  once: (process.env.NODE_ENV == 'production')
}))

// Redirect to environment-appropriate domain, if necessary
app.all('*', function(req, res, next) {
  if (config.header_host_port != req.headers.host) {
    var redirectUrl = 'http://' + config.header_host_port + req.url
    console.log('req.host = %s but config.header_host_port = %s; redirecting to %s...', req.host, config.header_host_port, redirectUrl)
    res.redirect(301, redirectUrl)
  } else {
    next('route')
  }
})

app.use(express.static(__dirname + '/public'))

app.get('/twitter-sign-in', controllers.twitter_sign_in.get)
app.get(config.twitter.oauth_callback_uri, controllers.twitter_sign_in_callback.get)

app.all('*', function(req, res, next) {
  var apiUrlRegexp = new RegExp("^" + config.restapi_proxy_baseuri_rel)
  if (req.url.match(apiUrlRegexp)) {

    var targetUri = config.restapi_baseuri + req.url.replace(apiUrlRegexp, '')

    var headers = req.headers
    headers.host = url.parse(config.restapi_baseuri).hostname

    console.log('Routing request %s %s to %s...', req.method, req.url, targetUri)

    req.pipe(request({
      method: req.method,
      uri: targetUri,
      headers: headers,
      followRedirect: false
    })).pipe(res)
      
  } else {
    next('route')
  }
})

// Catch-all<commit_msg>Removing debugging statement now that we know this works on Heroku :).<commit_after>var fs = require('fs'),
    express = require('express'),
    request = require('request'),
    url = require('url'),
    lessMiddleware = require('less-middleware'),
    config = require('config'),
    mustache = require('mustache'),
    controllers = require('./app/controllers')

var app = express()

app.use(express.compress())
app.use(express.cookieParser())
app.use(express.cookieSession({ secret: 'seger handrail' }))

app.use(lessMiddleware({
  src: __dirname + '/public',
  compress: (process.env.NODE_ENV == 'production'),
  once: (process.env.NODE_ENV == 'production')
}))

// Redirect to environment-appropriate domain, if necessary
app.all('*', function(req, res, next) {
  if (config.header_host_port != req.headers.host) {
    var redirectUrl = 'http://' + config.header_host_port + req.url
    console.log('req.host = %s but config.header_host_port = %s; redirecting to %s...', req.host, config.header_host_port, redirectUrl)
    res.redirect(301, redirectUrl)
  } else {
    next('route')
  }
})

app.use(express.static(__dirname + '/public'))

app.get('/twitter-sign-in', controllers.twitter_sign_in.get)
app.get(config.twitter.oauth_callback_uri, controllers.twitter_sign_in_callback.get)

app.all('*', function(req, res, next) {
  var apiUrlRegexp = new RegExp("^" + config.restapi_proxy_baseuri_rel)
  if (req.url.match(apiUrlRegexp)) {

    var targetUri = config.restapi_baseuri + req.url.replace(apiUrlRegexp, '')

    var headers = req.headers
    headers.host = url.parse(config.restapi_baseuri).hostname

    req.pipe(request({
      method: req.method,
      uri: targetUri,
      headers: headers,
      followRedirect: false
    })).pipe(res)
      
  } else {
    next('route')
  }
})

// Catch-all
{'fraction_non_alphanumeric': 0.16018619934282585, 'fraction_numerical': 0.0016429353778751369, 'mean_word_length': 4.024759284731775, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7162755', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1189, 'n_words': 235}