<commit_before>var express = require('express');
var httpProxy = require('http-proxy');
var http = require('http');
var https = require('https');
var path = require('path');
var fs = require('fs');

var app = express();

// all environments
app.set('port', process.env.PORT || 80);
app.set('httpsport', process.env.HTTPS_PORT || 443);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// redirect http to https
function requireHTTPS(req, res, next) {
	if (!req.secure) {
		return res.redirect(301, 'https://' + req.get('host') + req.url);
	}
	res.header('Strict-Transport-Security', 'max-age=31536000');
	next();
}

app.use(requireHTTPS);

var redirects = {
	//'router':'http://127.0.0.1:8081',
	'transmission':'http://127.0.0.1:9091',
	'torrent_files':'http://127.0.0.1:9980',
	'chunk':'http://127.0.0.1:9980',
	'icons':'http://127.0.0.1:9980',
	'map':'http://127.0.0.1:9980',
	//'xbmc':'http://127.0.0.1:4444',
};

var proxy = httpProxy.createProxyServer({});

function proxyRedirect(req, res, next) {
	var first = req.url.split('/')[1];
	if (redirects[first]) {
		return proxy.web(req, res, {
			target : redirects[first],
			headers : {
				host : 'www.bakker.pw:80'
			}
		});
	}
	next();
}

app.use(proxyRedirect);


//app.use(express.favicon());
app.use(express.favicon(path.join(__dirname, 'public/images/favicon.ico')));
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(require('stylus').middleware(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));

// development only
if ('development' == app.get('env')) {
	app.use(express.errorHandler());
}

// 404
app.use(require('./routes/404'));

// global jade properties
var imgSize = 24;
app.locals({
	imgSize: imgSize,
	domain: 'bakker.pw',
	navList: [
		{name:'Home', href:'/', img:'/images/'+imgSize+'/workspace-switcher.png'},
		{name:'Minecraft', href:'/minecraft', img:'/images/'+imgSize+'/minecraft.png'},
		{name:'Torrent', href:'/torrent', img:'/images/'+imgSize+'/transmission.png'},
		//{name:'XBMC', href:'/xbmc', img:'/images/'+imgSize+'/video-x-generic.png'},
		{name:'Mumble', href:'/mumble', img:'/images/'+imgSize+'/mumble.png'},
		//{name:'Router', href:'/router', img:'/images/'+imgSize+'/network-server.png'},
		{name:'About', href:'/about', img:'/images/'+imgSize+'/dialog-information.png'}<commit_msg>Stripped www.  Fixed apache redirects<commit_after>var express = require('express');
var httpProxy = require('http-proxy');
var http = require('http');
var https = require('https');
var path = require('path');
var fs = require('fs');

var DOMAIN = 'bakker.pw';

var app = express();

// all environments
app.set('port', process.env.PORT || 80);
app.set('httpsport', process.env.HTTPS_PORT || 443);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// redirect http to https
function requireHTTPS(req, res, next) {
	if (!req.secure) {
		return res.redirect(301, 'https://' + req.get('host') + req.url);
	}
	res.header('Strict-Transport-Security', 'max-age=31536000');
	next();
}

app.use(requireHTTPS);

function stripWWW(req, res, next) {
	if (req.get('host')) {
		if (req.get('host').indexOf('www.' + DOMAIN) !== -1) {
			return res.redirect('https://' + DOMAIN + req.url);
		}
	}
	next();
}
app.use(stripWWW);

var redirects = {
	//'router':'http://127.0.0.1:8081',
	'transmission':'http://127.0.0.1:9091',
	'torrent_files':'http://127.0.0.1:9980',
	'chunk':'http://127.0.0.1:9980',
	'icons':'http://127.0.0.1:9980',
	'map':'http://127.0.0.1:9980',
	//'xbmc':'http://127.0.0.1:4444',
};

var proxy = httpProxy.createProxyServer({});

function proxyRedirect(req, res, next) {
	var first = req.url.split('/')[1];
	if (redirects[first]) {
		try {
			return proxy.web(req, res, {
				target : redirects[first]
			});
		}
		catch(ex) {
			console.log('Caught from proxy web:' + ex);
		}
	}
	next();
}

app.use(proxyRedirect);


//app.use(express.favicon());
app.use(express.favicon(path.join(__dirname, 'public/images/favicon.ico')));
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(require('stylus').middleware(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));

// development only
if ('development' == app.get('env')) {
	app.use(express.errorHandler());
}

// 404
app.use(require('./routes/404'));

// global jade properties
var imgSize = 24;
app.locals({
	imgSize: imgSize,
	domain: DOMAIN,
	navList: [
		{name:'Home', href:'/', img:'/images/'+imgSize+'/workspace-switcher.png'},
		{name:'Minecraft', href:'/minecraft', img:'/images/'+imgSize+'/minecraft.png'},
		{name:'Torrent', href:'/torrent', img:'/images/'+imgSize+'/transmission.png'},
		//{name:'XBMC', href:'/xbmc', img:'/images/'+imgSize+'/video-x-generic.png'},
		{name:'Mumble', href:'/mumble', img:'/images/'+imgSize+'/mumble.png'},
		//{name:'Router', href:'/router', img:'/images/'+imgSize+'/network-server.png'},
		{name:'About', href:'/about', img:'/images/'+imgSize+'/dialog-information.png'}
{'fraction_non_alphanumeric': 0.24648294469069185, 'fraction_numerical': 0.03719406436693005, 'mean_word_length': 4.986159169550173, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 14, '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': '2377742', 'n_tokens_mistral': 2110, 'n_tokens_neox': 1952, 'n_words': 302}