<commit_before>var express = require('express');
var bodyParser = require('body-parser');
var sqlite = require('sqlite3');
var shortid = require('shortid');
var urlapi = require('url');
var validator = require('validator');
var RateLimit = require('express-rate-limit');

var app = express();
const PORT = 80;
const ROUTE_LIFESPAN = 600;
const DB_NAME = 'routes.db';

//set up express server configuration
app.set('view engine', 'pug');
app.locals.pretty = true;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

//configure rate limiter
var limiter = new RateLimit({
  windowMs: 15*60*1000,
  max: 100,
  delayMs: 100
});
app.use(limiter);

//initialize sqlite database
var db = new sqlite.Database(DB_NAME);
db.run("CREATE TABLE IF NOT EXISTS Routes "
       + "(id TEXT, url TEXT, hits INTEGER, created_on INTEGER)");

//root directory, show index page
app.get('/', function(req, res) {
  res.render('index', { title: 'URL Shortener' });
});

//handles POST requests to "/submit"
//used for creating new entries in routes database
app.post('/submit', function(req, res) {
  var url = req.body.url;
  urlInfo = urlapi.parse(url);
  if (urlInfo.protocol == null && url.length > 0) {
    url = 'http://' + url;
  }
  if (validator.isURL(url)) {
    var newID = shortid.generate();
    var timestamp = new Date().getTime() / 1000;<commit_msg>logging<commit_after>var express = require('express');
var bodyParser = require('body-parser');
var sqlite = require('sqlite3');
var shortid = require('shortid');
var urlapi = require('url');
var validator = require('validator');
var RateLimit = require('express-rate-limit');

var app = express();
const PORT = 80;
const ROUTE_LIFESPAN = 600;
const DB_NAME = 'routes.db';

//set up express server configuration
app.set('view engine', 'pug');
app.locals.pretty = true;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

//configure rate limiter
var limiter = new RateLimit({
  windowMs: 15*60*1000,
  max: 100,
  delayMs: 100
});
app.use(limiter);

//initialize sqlite database
var db = new sqlite.Database(DB_NAME);
db.run("CREATE TABLE IF NOT EXISTS Routes "
       + "(id TEXT, url TEXT, hits INTEGER, created_on INTEGER)");

//root directory, show index page
app.get('/', function(req, res) {
  res.render('index', { title: 'URL Shortener' });
});

//handles POST requests to "/submit"
//used for creating new entries in routes database
app.post('/submit', function(req, res) {
  var url = req.body.url;
  console.log('POST received: ' + req);
  urlInfo = urlapi.parse(url);
  if (urlInfo.protocol == null && url.length > 0) {
    url = 'http://' + url;
  }
  if (validator.isURL(url)) {
    var newID = shortid.generate();
    var timestamp = new Date().getTime() / 1000;
{'fraction_non_alphanumeric': 0.16486681065514758, 'fraction_numerical': 0.017998560115190784, 'mean_word_length': 4.375241779497099, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '28447', 'n_tokens_mistral': 954, 'n_tokens_neox': 896, 'n_words': 268}