{"size": 748, "ext": "js", "max_stars_repo_path": "router/index.js", "max_stars_repo_name": "trawor/template-node-koa", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "router/index.js", "max_issues_repo_name": "trawor/template-node-koa", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "router/index.js", "max_forks_repo_name": "trawor/template-node-koa", "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": 23.375, "max_line_length": 58, "alphanum_fraction": 0.5882352941}
const fs = require('fs');
const router = require('koa-router')();

const pkginfo = require('../package.json');

fs.readdirSync(__dirname).forEach((file) => {
  if (file !== 'index.js') {
    // eslint-disable-next-line
    const subR = require(`./${file}`);
    router.use('/', subR.routes(), subR.allowedMethods());
  }
});

const rmap = {
  server: pkginfo.name,
  version: pkginfo.version,
};
const ra = router.stack.map((i) => {
  const ss = i.methods.filter(item => item !== 'HEAD');
  return `${ss.join('|')} ${i.path}`;
}).filter(item => item !== ' /');
rmap.router = ra;
console.info(`Server Routers:\n${ra.join('\n')}`);

router.get('/api', (ctx) => {
  const ret = rmap;
  ret.ip = ctx.ip;
  ctx.body = ret;
});

module.exports = router;
