<commit_before>import glob from 'glob'
import Router from 'koa-router'

exports = module.exports = function initModules(app) {
  glob(`${__dirname}/*`, { ignore: '**/index.js' }, (err, matches) => {
    if (err) { throw err }

    matches.forEach((mod) => {
      const routerConfig = require(`${mod}/router`).default
      const router = new Router({ prefix: routerConfig.base })

      for (const [key, props] of Object.entries(routerConfig)) {
        if (key === 'base') { continue }

        const {
          method = '',
          route = '',
          middleware = [],
          controller
        } = props

        router[method.toLowerCase()](route, controller)

        app
          .use(router.routes())
          .use(router.allowedMethods())
      }
    })
  })
}<commit_msg>Mount middleware stack per route<commit_after>import glob from 'glob'
import Router from 'koa-router'
import convert from 'koa-convert'

exports = module.exports = function initModules(app) {
  glob(`${__dirname}/*`, { ignore: '**/index.js' }, (err, matches) => {
    if (err) { throw err }

    matches.forEach((mod) => {
      const routerConfig = require(`${mod}/router`).default
      const router = new Router({ prefix: routerConfig.base })

      for (const [key, props] of Object.entries(routerConfig)) {
        if (key === 'base') { continue }

        const {
          method = '',
          route = '',
          middleware = [],
          controller
        } = props

        router[method.toLowerCase()](route, ...middleware, controller)

        app
          .use(router.routes())
          .use(router.allowedMethods())
      }
    })
  })
}
{'fraction_non_alphanumeric': 0.15696969696969698, 'fraction_numerical': 0.0, 'mean_word_length': 2.302, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7208473', 'n_tokens_mistral': 476, 'n_tokens_neox': 474, 'n_words': 113}