{"size": 855, "ext": "js", "max_stars_repo_path": "server/api/index.js", "max_stars_repo_name": "billpatrianakos/felix-website", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server/api/index.js", "max_issues_repo_name": "billpatrianakos/felix-website", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "server/api/index.js", "max_forks_repo_name": "billpatrianakos/felix-website", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.5357142857, "max_line_length": 102, "alphanum_fraction": 0.6105263158}
// API Routes
// -----------
// Routes that respond to API requests

'use strict';

const _           = require('lodash');
const fs          = require('fs');
const cors        = require('cors');
const excluded    = ['index'];
const corsConfig  = require(__dirname + '/../config/app')[process.env.NODE_ENV || 'development'].cors;

module.exports = (app) => {
  // Enable CORS for all API routes
  app.use(cors(corsConfig));

  // Loop through all API routes and call app.use() on each of them
  fs.readdirSync(__dirname).forEach((file) => {
    // Remove extension from file name
    var basename = file.split('.')[0];

    // Only load files that aren't directories and aren't blacklisted
    if (!fs.lstatSync(__dirname + '/' + file).isDirectory() && !_.includes(excluded, file)) {
      app.use('/api/' + basename, require('./' + file));
    }
  });
};
