var fs = require('fs')
  , modules = []

fs.readdirSync(__dirname)
  .forEach((module) => {
    if (module === 'index.js') return;

    var moduleName = module.replace(/\.js$/, '')

    modules.push(require('./' + moduleName))
  })

module.exports = (app) => modules.map( module => {
    module.weight = module.weight || 0
    module.path = module.path || '/'
    return module
  }).sort((module1, module2) => module1.weight < module2.weight)
  .forEach( module => module.policy(app))