<commit_before>var bodyParser = require('body-parser'),
	constants = require('../../lib/constants'),
	cookieParser = require('cookie-parser'),
	express = require('express'),
	fs = require('fs'),
	https = require('https'),
	path = require('path');

var certDir = path.join(__dirname,'..','fixtures'),
	key = fs.readFileSync(path.join(certDir, 'mw-test-server-key.pem')),
	cert = fs.readFileSync(path.join(certDir, 'mw-test-server-cert.pem'));

// prep express
var app = express();
app.listen = function() {
	var server = https.createServer({
		key: key,
		cert: cert
	}, this);
	return server.listen.apply(server, arguments);
};
app.use(bodyParser());
app.use(cookieParser());

// auth route
app.post('/api/v1/auth/login', function(req, res) {
	var user = req.param('username'),
		pass = req.param('password');

	// auth
	if ((user !== 'test' && user !== 'nocookie') || pass !== '<PASSWORD>') {
		return res.status(400).type('text/plain').send('invalid username/password combo');
	}

	// add cookie and send
	if (user !== 'nocookie') {
		res.cookie('connect.sid', 'sessioncookie');
	}
	return res.status(200).type('text/plain').send('logged in');
});

// enable route
app.post('/api/v1/apibuilder/enable', function(req, res) {
	var appId = req.param('appId');

	// sent a cookie, right?
	if (!req.cookies['connect.sid']) {
		return res.status(400).type('text/plain').send('no cookie');
	}

	// make sure we have an appId
	if (!appId) {
		return res.status(400).type('text/plain').send('appId is a required parameter');
	}

	// make sure appId exists
	if (appId === 'bad.api') {
		return res.status(500).type('text/plain').send('failed to load MW keys');
	} else if (appId !== 'ti.mw.todo') {
		return res.status(400).type('text/plain').send('appId does not exist');
	}

	// send keys via fixture data
	try {
		return res.status(200).type('application/json').send({
			success: true,
			result: {
				keys: {<commit_msg>use constant for url path<commit_after>var bodyParser = require('body-parser'),
	constants = require('../../lib/constants'),
	cookieParser = require('cookie-parser'),
	express = require('express'),
	fs = require('fs'),
	https = require('https'),
	path = require('path');

var certDir = path.join(__dirname,'..','fixtures'),
	key = fs.readFileSync(path.join(certDir, 'mw-test-server-key.pem')),
	cert = fs.readFileSync(path.join(certDir, 'mw-test-server-cert.pem'));

// prep express
var app = express();
app.listen = function() {
	var server = https.createServer({
		key: key,
		cert: cert
	}, this);
	return server.listen.apply(server, arguments);
};
app.use(bodyParser());
app.use(cookieParser());

// auth route
app.post('/api/v1/auth/login', function(req, res) {
	var user = req.param('username'),
		pass = req.param('password');

	// auth
	if ((user !== 'test' && user !== 'nocookie') || pass !== 'test') {
		return res.status(400).type('text/plain').send('invalid username/password combo');
	}

	// add cookie and send
	if (user !== 'nocookie') {
		res.cookie('connect.sid', 'sessioncookie');
	}
	return res.status(200).type('text/plain').send('logged in');
});

// enable route
app.post(constants.ENABLE_API, function(req, res) {
	var appId = req.param('appId');

	// sent a cookie, right?
	if (!req.cookies['connect.sid']) {
		return res.status(400).type('text/plain').send('no cookie');
	}

	// make sure we have an appId
	if (!appId) {
		return res.status(400).type('text/plain').send('appId is a required parameter');
	}

	// make sure appId exists
	if (appId === 'bad.api') {
		return res.status(500).type('text/plain').send('failed to load MW keys');
	} else if (appId !== 'ti.mw.todo') {
		return res.status(400).type('text/plain').send('appId does not exist');
	}

	// send keys via fixture data
	try {
		return res.status(200).type('application/json').send({
			success: true,
			result: {
				keys: {
{'fraction_non_alphanumeric': 0.20677966101694914, 'fraction_numerical': 0.011734028683181226, 'mean_word_length': 4.240437158469946, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '3178323', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1305, 'n_words': 290}