{"size": 947, "ext": "js", "max_stars_repo_path": "server/middlewareMapper.js", "max_stars_repo_name": "lalanimau/ethereum_real_estate", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server/middlewareMapper.js", "max_issues_repo_name": "lalanimau/ethereum_real_estate", "max_issues_repo_issues_event_min_datetime": "2020-07-18T10:39:33.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-18T10:39:33.000Z", "max_forks_repo_path": "server/middlewareMapper.js", "max_forks_repo_name": "akashg-solulab/ethereum_real_estate", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 36.4230769231, "max_line_length": 123, "alphanum_fraction": 0.722280887}
'use strict';

const path = require('path');
const log = require('./logger');

const middlewareRootPath = 'api/middlewares/';
const middlewareList = require('./utils').getFolderFilesRecursivelyWithPath(middlewareRootPath);

let importedMiddleware = {};

middlewareList.forEach((middleware) => {
  let folderPath = middleware.folder.split(path.normalize(middlewareRootPath))[1] || '';
  let middlewareFileName = middleware.file.split('.')[0];
  let fullFilePath = `../${middleware.folder}${middleware.file}`;

  try {
    importedMiddleware[`${folderPath}${middlewareFileName}`] = require(fullFilePath);
    log.info(`Middleware :: loading middleware "${path.normalize(middleware.folder) + middlewareFileName}"`);
  } catch(error) {
    log.error(`Middleware :: error loading middleware "${path.normalize(middleware.folder) + middlewareFileName}"`, error);
    process.exit(1); // eslint-disable-line
  }
});
 
module.exports = importedMiddleware;
