<commit_before>var express = require('express');
var config = require('config');
var db = require('./db')();
var session = require('express-session');
var MongoStore = require('connect-mongo')(session);
var app = express();
var pages = require('./controllers/page');
var users = require('./controllers/user');

app.disable('x-powered-by');
app.set('view engine', 'jade');

app.locals.basedir = './';
app.locals.pretty = true;
app.locals.domain = config.domain;

app.use(require('compression')());
app.use(express.static('public'));
app.use(require('body-parser').urlencoded({ extended: false }));

app.use(session({
	name: 'session',
	secret: 'foo',
	resave: false,
	saveUninitialized: true,
	store: new MongoStore({ mongooseConnection: db })
}));

app.use(function (req, res, next) {
	var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
	if (ip.startsWith('::ffff:')) ip = ip.substring(7);
	res.locals.ip = ip;
	res.locals.loggedIn = users.checkSession(req);
	res.locals.user = req.session.user;

	next();
});

app.get('/', pages.home);
app.post('/', pages.homePost);
app.get('/about', pages.about);<commit_msg>Better session checking<commit_after>var express = require('express');
var config = require('config');
var wrap = require('co-express');
var db = require('./db')();
var session = require('express-session');
var MongoStore = require('connect-mongo')(session);
var app = express();
var pages = require('./controllers/page');
var users = require('./controllers/user');

app.disable('x-powered-by');
app.set('view engine', 'jade');

app.locals.basedir = './';
app.locals.pretty = true;
app.locals.domain = config.domain;

app.use(require('compression')());
app.use(express.static('public'));
app.use(require('body-parser').urlencoded({ extended: false }));

app.use(session({
	name: 'session',
	secret: 'foo',
	resave: false,
	saveUninitialized: true,
	store: new MongoStore({ mongooseConnection: db })
}));

app.use(wrap(function* (req, res, next) {
	var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
	if (ip.startsWith('::ffff:')) ip = ip.substring(7);
	res.locals.ip = ip;

	if (users.checkSession(req)) {
		users.setSession(req, yield users.getUser(req, false));
	}

	res.locals.loggedIn = users.checkSession(req);
	res.locals.user = req.session.user;

	next();
}));

app.get('/', pages.home);
app.post('/', pages.homePost);
app.get('/about', pages.about);
{'fraction_non_alphanumeric': 0.21144278606965175, 'fraction_numerical': 0.0008291873963515755, 'mean_word_length': 5.504043126684636, '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': '4051342', 'n_tokens_mistral': 825, 'n_tokens_neox': 820, 'n_words': 164}