How to use the koa-router.define function in koa-router

To help you get started, we’ve selected a few koa-router examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github garbin / koapi / src / router.es View on Github external
import Router from 'koa-router'
import compose from 'koa-compose'
import Model from './model'
import Collection from 'bookshelf/lib/collection'
import paginate from 'koa-pagination'
import convert from 'koa-convert'
import joi_to_json_schema from 'joi-to-json-schema'
import jsf from 'json-schema-faker'
import Joi from 'joi'
import _ from 'lodash'
import pluralize from 'pluralize'

Router.define = function (options) {
  let {setup, ...rest} = options;
  if (_.isFunction(options)) {
    setup = options;
    options = {};
  }
  options = rest || options;
  setup = setup || (router => router)
  let router = new Router(options);
  setup(router);

  return router;
}

Router.prototype.schema = function () {
  return null;
}

koa-router

Router middleware for koa. Maintained by Forward Email and Lad.

MIT
Latest version published 2 months ago

Package Health Score

87 / 100
Full package analysis