<commit_before>var express = require('express');
var bodyParser = require('body-parser');
var mongo = require('mongodb');
var logfmt = require('logfmt');
var ObjectID = require('mongodb').ObjectID;

var app = express();
var router = express.Router();

var version = "0.1";

app.use(bodyParser());
app.use(logfmt.bodyParserStream());
app.use('/api/' + version, router);
app.use("/", express.static(__dirname + '/public'));

var mongoUri = process.env.MONGOLAB_URI ||
  process.env.MONGO_URL ||
  'mongodb://localhost/mydb';


console.log(mongoUri);


// Middleware
router.use(function(req, res, next) {
	// global middleware
	res.header("Access-Control-Allow-Origin", "*");
	res.header("Access-Control-Allow-Headers", "X-Requested-With");
	next();
});


router.route('/search')
	.all(function(req, res, next) {
	  // route-specific middleware
	  next();
	})
	.get(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.put(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.post(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.delete(function(req, res, next) {
	  next(new Error('not implemented'));
	});


// Create


// Read

router.route('/features')
	.all(function(req, res, next) {
	  // route-specific middleware
	  next();
	})
	.get(function(req, res, next) {
	  mongo.Db.connect(mongoUri, function (err, db) {
		   db.collection('features', function(er, collection) {
		     collection.find({}).toArray(function(er,rs) {
		       res.send(rs);
		     });
		   });
		 });
	})
	.put(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.post(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.delete(function(req, res, next) {
	  next(new Error('not implemented'));
	});


router.route('/features/:featureid')
	.all(function(req, res, next) {
	  // route-specific middleware
	  next();
	})
	.get(function(req, res, next) {
		mongo.Db.connect(mongoUri, function (err, db) {
			db.collection('features', function(er, collection) {
				try {
					var tempObjectID = new ObjectID(req.params.featureid);
				} catch (e) {
					var tempObjectID = 0;
				}
				collection.find({"_id": tempObjectID}).toArray(function(er,rs) {
					if (er) {
						res.send(er);
					} else {
						if (rs.length == 1) {
							res.send(rs[0]);
						} else {
							res.send(rs);
						}
					}
		    	});
			});
		});
	})
	.put(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.post(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.delete(function(req, res, next) {
	  next(new Error('not implemented'));
	});


router.route('/venues')
	.all(function(req, res, next) {
	  // route-specific middleware
	  next();
	})
	.get(function(req, res, next) {
	  mongo.Db.connect(mongoUri, function (err, db) {
		   db.collection('venues', function(er, collection) {
		     collection.find({}).toArray(function(er,rs) {
		       res.send(rs);
		     });
		   });
		 });
	})
	.put(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.post(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.delete(function(req, res, next) {
	  next(new Error('not implemented'));
	});


router.route('/venues/:venueid')
	.all(function(req, res, next) {
	  // route-specific middleware
	  next();
	})
	.get(function(req, res, next) {
		mongo.Db.connect(mongoUri, function (err, db) {
			db.collection('venues', function(er, collection) {
				try {
					var tempObjectID = new ObjectID(req.params.venueid);
				} catch (e) {
					var tempObjectID = 0;
				}
				collection.find({"_id": tempObjectID}).toArray(function(er,rs) {
					if (er) {
						res.send(er);
					} else {
						if (rs.length == 1) {
							res.send(rs[0]);
						} else {
							res.send(rs);
						}
					}
		    	});
			});
		});
	})
	.put(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.post(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.delete(function(req, res, next) {
	  next(new Error('not implemented'));
	});


router.route('/showings')
	.all(function(req, res, next) {
		// route-specific middleware
		next();
	})
	.get(function(req, res, next) {
	  mongo.Db.connect(mongoUri, function (err, db) {
		   db.collection('showings', function(er, collection) {
		     collection.find({}).toArray(function(er,rs) {
		       res.send(rs);
		     });
		   });
		 });
	})
	.put(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.post(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.delete(function(req, res, next) {
	  next(new Error('not implemented'));
	});


router.route('/showings/:showingid')
	.all(function(req, res, next) {
	  // route-specific middleware
	  next();
	})
	.get(function(req, res, next) {
		mongo.Db.connect(mongoUri, function (err, db) {
			db.collection('showings', function(er, collection) {
				try {
					var tempObjectID = new ObjectID(req.params.showingid);
				} catch (e) {
					var tempObjectID = 0;
				}
				collection.find({"_id": tempObjectID}).toArray(function(er,rs) {
					if (er) {
						res.send(er);
					} else {
						if (rs.length == 1) {
							res.send(rs[0]);
						} else {
							res.send(rs);
						}<commit_msg>changed errors and unknown ids from sending empty list to sending empty json<commit_after>var express = require('express');
var bodyParser = require('body-parser');
var mongo = require('mongodb');
var logfmt = require('logfmt');
var ObjectID = require('mongodb').ObjectID;

var app = express();
var router = express.Router();

var version = "0.1";

app.use(bodyParser());
app.use(logfmt.bodyParserStream());
app.use('/api/' + version, router);
app.use("/", express.static(__dirname + '/public'));

var mongoUri = process.env.MONGOLAB_URI ||
  process.env.MONGO_URL ||
  'mongodb://localhost/mydb';


console.log(mongoUri);


// Middleware
router.use(function(req, res, next) {
	// global middleware
	res.header("Access-Control-Allow-Origin", "*");
	res.header("Access-Control-Allow-Headers", "X-Requested-With");
	next();
});


router.route('/search')
	.all(function(req, res, next) {
	  // route-specific middleware
	  next();
	})
	.get(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.put(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.post(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.delete(function(req, res, next) {
	  next(new Error('not implemented'));
	});


// Create


// Read

router.route('/features')
	.all(function(req, res, next) {
	  // route-specific middleware
	  next();
	})
	.get(function(req, res, next) {
	  mongo.Db.connect(mongoUri, function (err, db) {
		   db.collection('features', function(er, collection) {
		     collection.find({}).toArray(function(er,rs) {
		       res.send(rs);
		     });
		   });
		 });
	})
	.put(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.post(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.delete(function(req, res, next) {
	  next(new Error('not implemented'));
	});


router.route('/features/:featureid')
	.all(function(req, res, next) {
	  // route-specific middleware
	  next();
	})
	.get(function(req, res, next) {
		mongo.Db.connect(mongoUri, function (err, db) {
			db.collection('features', function(er, collection) {
				try {
					var tempObjectID = new ObjectID(req.params.featureid);
				} catch (e) {
					var tempObjectID = 0;
				}
				collection.findOne({"_id": tempObjectID}, function(er,rs) {
					if (er || !rs) {
						res.send({});
					} else {
						res.send(rs);
					}
		    	});
			});
		});
	})
	.put(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.post(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.delete(function(req, res, next) {
	  next(new Error('not implemented'));
	});


router.route('/venues')
	.all(function(req, res, next) {
	  // route-specific middleware
	  next();
	})
	.get(function(req, res, next) {
	  mongo.Db.connect(mongoUri, function (err, db) {
		   db.collection('venues', function(er, collection) {
		     collection.find({}).toArray(function(er,rs) {
		       res.send(rs);
		     });
		   });
		 });
	})
	.put(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.post(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.delete(function(req, res, next) {
	  next(new Error('not implemented'));
	});


router.route('/venues/:venueid')
	.all(function(req, res, next) {
	  // route-specific middleware
	  next();
	})
	.get(function(req, res, next) {
		mongo.Db.connect(mongoUri, function (err, db) {
			db.collection('venues', function(er, collection) {
				try {
					var tempObjectID = new ObjectID(req.params.venueid);
				} catch (e) {
					var tempObjectID = 0;
				}
				collection.findOne({"_id": tempObjectID}, function(er,rs) {
					if (er || !rs) {
						res.send({});
					} else {
						res.send(rs);
					}
		    	});
			});
		});
	})
	.put(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.post(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.delete(function(req, res, next) {
	  next(new Error('not implemented'));
	});


router.route('/showings')
	.all(function(req, res, next) {
		// route-specific middleware
		next();
	})
	.get(function(req, res, next) {
	  mongo.Db.connect(mongoUri, function (err, db) {
		   db.collection('showings', function(er, collection) {
		     collection.find({}).toArray(function(er,rs) {
		       res.send(rs);
		     });
		   });
		 });
	})
	.put(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.post(function(req, res, next) {
	  next(new Error('not implemented'));
	})
	.delete(function(req, res, next) {
	  next(new Error('not implemented'));
	});


router.route('/showings/:showingid')
	.all(function(req, res, next) {
	  // route-specific middleware
	  next();
	})
	.get(function(req, res, next) {
		mongo.Db.connect(mongoUri, function (err, db) {
			db.collection('showings', function(er, collection) {
				try {
					var tempObjectID = new ObjectID(req.params.showingid);
				} catch (e) {
					var tempObjectID = 0;
				}
				collection.findOne({"_id": tempObjectID}, function(er,rs) {
					if (er || !rs) {
						res.send({});
					} else {
						res.send(rs);
{'fraction_non_alphanumeric': 0.19539454668079775, 'fraction_numerical': 0.001541574332787359, 'mean_word_length': 3.301699129714049, 'pattern_counts': {'":': 6, '<': 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': '386558', 'n_tokens_mistral': 4161, 'n_tokens_neox': 3630, 'n_words': 693}