<commit_before>'use strict';

const fs = require('fs');
const express = require('express');
const expressValidator = require('express-validator');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const config = require('./config');
const authRoute = require('./api/routes/auth.route');
const checkAuthentication = require('./api/middlewares/authentication.middleware');
const checkContentType = require('./api/middlewares/content-type.middleware');
const notFound = require('./api/middlewares/not-found.middleware');

const app = express();

mongoose.Promise = global.Promise;
mongoose.connect(`mongodb://${config.host}/${config.database}`, err => {
  if (err) {
    return console.log(`Error connecting with MongoDB: ${err}`)
  }
  console.log('MongoDB connected');
});

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

app.use(expressValidator());
app.use(checkContentType);

authRoute(app);

app.use(checkAuthentication);

app.use((req, res, next) => {
  req.checkQuery('page', "Must be an integer with '1' as min value")
    .optional().isInt({ min: 1 });
  req.checkQuery('limit', "Must be an integer with '1' as min value")
    .optional().isInt({ min: 1 });

  req.getValidationResult()
    .then(errors => {
      if (!errors.isEmpty()) {
        return res.status(400).json({ errors: errors.array() });
      }
      return next();
    });
});

const routesPath = './api/routes/';
fs.readdirSync(routesPath).forEach(filename => {
  if (filename !== 'auth.route.js') {
    const route = require(routesPath + filename);
    route(app);
  }
});

app.use(notFound);

app.listen(config.port, err => {
  if (err) {
    return console.log(`Error starting REST API server: ${err}`)
  }
  console.log('REST API server started on: '
    + `${config.protocol}://${config.host}:${config.port}`);
});

module.exports = app;
<commit_msg>Move query param middleware to correct folder<commit_after>'use strict';

const fs = require('fs');
const express = require('express');
const expressValidator = require('express-validator');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const config = require('./config');
const authRoute = require('./api/routes/auth.route');
const checkAuthentication = require('./api/middlewares/authentication.middleware');
const checkContentType = require('./api/middlewares/content-type.middleware');
const checkQueryParams = require('./api/middlewares/query-param.middleware');
const notFound = require('./api/middlewares/not-found.middleware');

const app = express();

mongoose.Promise = global.Promise;
mongoose.connect(`mongodb://${config.host}/${config.database}`, err => {
  if (err) {
    return console.log(`Error connecting with MongoDB: ${err}`)
  }
  console.log('MongoDB connected');
});

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(expressValidator());
app.use(checkContentType);

authRoute(app);

app.use(checkAuthentication);
app.use(checkQueryParams);

const routesPath = './api/routes/';
fs.readdirSync(routesPath).forEach(filename => {
  if (filename !== 'auth.route.js') {
    const route = require(routesPath + filename);
    route(app);
  }
});

app.use(notFound);

app.listen(config.port, err => {
  if (err) {
    return console.log(`Error starting REST API server: ${err}`)
  }
  console.log('REST API server started on: '
    + `${config.protocol}://${config.host}:${config.port}`);
});

module.exports = app;

{'fraction_non_alphanumeric': 0.18371428571428572, 'fraction_numerical': 0.002, 'mean_word_length': 4.864321608040201, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2513249', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1080, 'n_words': 227}