<commit_before>var express = require('express');
var router = express.Router();

var mongoose = require('mongoose');
var Post = mongoose.model('Post');
var Comment = mongoose.model('Comment');

router.get('/posts', function(req, res, next) {
	Post.find(function(err, posts) {
		if (err) {
			return next(err);
		}
		res.json(posts);
	});
});

router.post('/posts', function(req, res, next) {
	var post = new Post(req.body);

	post.save(function(err, post) {
		if (err) {
			return next(err);
		}
		res.json(post);
	});
});

module.exports = router;<commit_msg>Pre-loading post object and create single post page.<commit_after>var express = require('express');
var router = express.Router();

var mongoose = require('mongoose');
var Post = mongoose.model('Post');
var Comment = mongoose.model('Comment');

router.param('post', function(req, res, next, id) {
	var query = Post.findById(id);

	query.exec(function(err, post) {
		if (err) {
			return next(err);
		}
		if (!post) {
			return next(new Error('can\'t find post'));
		}
		req.post = post;
		return next();
	});
});

router.get('/posts', function(req, res, next) {
	Post.find(function(err, posts) {
		if (err) {
			return next(err);
		}
		res.json(posts);
	});
});

router.post('/posts', function(req, res, next) {
	var post = new Post(req.body);

	post.save(function(err, post) {
		if (err) {
			return next(err);
		}
		res.json(post);
	});
});

router.get('/posts/:post', function(req, res, next) {
	res.json(req.post);
});

module.exports = router;
{'fraction_non_alphanumeric': 0.1976127320954907, 'fraction_numerical': 0.0, 'mean_word_length': 4.185567010309279, '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': '6514050', 'n_tokens_mistral': 569, 'n_tokens_neox': 543, 'n_words': 122}