<commit_before>var connect = require('connect');
var request = require('request');
var citeproc = require('./citeproc');
var doi = require('./doi');
var settings = require('./settings');

function init() {
	console.log("creating server...");

	var server = connect();
	server.use(connect.query());
	server.use(connect.logger());
	server.use(connect.static('./html'));

	server.use('/styles', listHandler(citeproc.getStyles()));
	server.use('/locales', listHandler(citeproc.getLocales()));
	server.use('/format', formatHandler);

	server.listen(settings.port);
	console.log("server listening on port " + settings.port + ".");
}

function listHandler(array) {
	return function(req, res) {
		var json = JSON.stringify(array);
		sendResponse(res, 200, json, {
			"Content-Type" : "application/json"
		});
	};
}

function formatHandler(req, res) {
	var query = req.query;
	var doi = query.doi;
	if (doi == undefined)
		sendResponse(res, 400, "doi param required");
	else {
		require("./doi").resolve(
				doi,
				function(data) {
					try {
						item = JSON.parse(data);
						citeproc.format(item, query.style, query.lang,
								function(text) {
									sendResponse(res, 200, text);
								}, function(msg) {
									sendResponse(res, 400, msg);
								});
					} catch (err) {<commit_msg>implement basic post handler<commit_after>var connect = require('connect');
var request = require('request');
var citeproc = require('./citeproc');
var doi = require('./doi');
var settings = require('./settings');

function init() {
	console.log("creating server...");

	var server = connect();
	server.use(connect.query());
	server.use(connect.logger());
	server.use(connect.static('./html'));
	server.use(connect.json());

	server.use('/styles', listHandler(citeproc.getStyles()));
	server.use('/locales', listHandler(citeproc.getLocales()));
	server.use('/format', method("GET", formatHandler));
	server.use('/format', method("POST", formatPostHandler));

	server.listen(settings.port);
	console.log("server listening on port " + settings.port + ".");
}

function listHandler(array) {
	return function(req, res) {
		var json = JSON.stringify(array);
		sendResponse(res, 200, json, {
			"Content-Type" : "application/json"
		});
	};
}

function method(method, handler) {
	return function(req, res, next) {
		if (method == req.method)
			handler(req, res, next);
		else
			next();
	};
}

function formatPostHandler(req, res) {
	console.log(req.body);
	citeproc.format(req.body, req.query.style, req.query.lang,
			function(text) {
				sendResponse(res, 200, text);
			}, function(msg) {
				sendResponse(res, 400, msg);
			});
}

function formatHandler(req, res) {
	var query = req.query;
	console.log(req.body);
	var doi = query.doi;
	if (doi == undefined)
		sendResponse(res, 400, "doi param required");
	else {
		require("./doi").resolve(
				doi,
				function(data) {
					try {
						req.body = JSON.parse(data);
						formatPostHandler(req, res);
					} catch (err) {
{'fraction_non_alphanumeric': 0.182277628032345, 'fraction_numerical': 0.008086253369272238, 'mean_word_length': 4.075213675213675, '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': '7006324', 'n_tokens_mistral': 1103, 'n_tokens_neox': 950, 'n_words': 204}