index.js
function toServer (router) {
  assert.equal(typeof router, 'function')

  const syms = getOwnSymbols(router)
  const sym = syms.length ? syms[0] : router._sym
  assert.ok(sym, 'router should be an instance of wayfarer')

  emit._subrouters = router._subrouters
  emit._routes = router._routes
  emit[sym] = true
  emit.emit = emit
  emit.on = on

  return emit

  // match a route and execute the corresponding callback
  // (obj, obj) -> null
  // original: {path, params parentDefault}
  function emit (route, req, res) {
    assert.equal(typeof route, 'string')
    assert.ok(req, 'no req specified')

    if (!req._ssa) {
      assert.ok(res, 'no res specified')
    }

    // handle server init
    if (isReq(req) && isRes(res)) {
      const ssa = createSsa({}, req, res)
      const dft = { node: { cb: [ router._default ] } }
      return router(route, ssa, dft)
    }

    // handle subrouter
    const params = req
    const parentDefault = res
    router(route, params, parentDefault)
  }

  // register a new route on a method
  // (str, obj) -> obj
  function on (route, methods) {
    assert.equal(typeof route, 'string')
    methods = methods || {}

    // mount subrouter
    if (methods[sym]) return router.on(route, methods)

    assert.equal(typeof methods, 'object')

    // mount http methods
    router.on(route, function (args) {
      demuxSsa(args, function (req, res, params) {
        const meth = methodist(req, defaultFn, methods)
        meth(req, res, params)

        // default function to call if methods don't match
        // null -> null
        function defaultFn () {
          router._default(args)
        }
      })
    })
    return emit
  }
}
function toServer (router) {
  assert.equal(typeof router, 'function')

  const syms = getOwnSymbols(router)
  const sym = syms.length ? syms[0] : router._sym
  assert.ok(sym, 'router should be an instance of wayfarer')

  emit._subrouters = router._subrouters
  emit._routes = router._routes
  emit[sym] = true
  emit.emit = emit
  emit.on = on

  return emit

  // match a route and execute the corresponding callback
  // (obj, obj) -> null
  // original: {path, params parentDefault}
  function emit (route, req, res) {
    assert.equal(typeof route, 'string')
    assert.ok(req, 'no req specified')

    if (!req._ssa) {
      assert.ok(res, 'no res specified')
    }

    // handle server init
    if (isReq(req) && isRes(res)) {
      const ssa = createSsa({}, req, res)
      const dft = { node: { cb: [ router._default ] } }
      return router(route, ssa, dft)
    }

    // handle subrouter
    const params = req
    const parentDefault = res
    router(route, params, parentDefault)
  }

  // register a new route on a method
  // (str, obj) -> obj
  function on (route, methods) {
    assert.equal(typeof route, 'string')
    methods = methods || {}

    // mount subrouter
    if (methods[sym]) return router.on(route, methods)

    assert.equal(typeof methods, 'object')

    // mount http methods
    router.on(route, function (args) {
      demuxSsa(args, function (req, res, params) {
        const meth = methodist(req, defaultFn, methods)
        meth(req, res, params)

        // default function to call if methods don't match
        // null -> null
        function defaultFn () {
          router._default(args)
        }
      })
    })
    return emit
  }
}
function toServer ( router ) { assert . equal ( typeof router , 'function' ) const syms = getOwnSymbols ( router ) const sym = syms . length ? syms [ 0 ] : router . _sym assert . ok ( sym , 'router should be an instance of wayfarer' ) emit . _subrouters = router . _subrouters emit . _routes = router . _routes emit [ sym ] = true emit . emit = emit emit . on = on return emit // match a route and execute the corresponding callback // (obj, obj) -> null // original: {path, params parentDefault} function emit ( route , req , res ) { assert . equal ( typeof route , 'string' ) assert . ok ( req , 'no req specified' ) if ( ! req . _ssa ) { assert . ok ( res , 'no res specified' ) } // handle server init if ( isReq ( req ) && isRes ( res ) ) { const ssa = createSsa ( { } , req , res ) const dft = { node : { cb : [ router . _default ] } } return router ( route , ssa , dft ) } // handle subrouter const params = req const parentDefault = res router ( route , params , parentDefault ) } // register a new route on a method // (str, obj) -> obj function on ( route , methods ) { assert . equal ( typeof route , 'string' ) methods = methods || { } // mount subrouter if ( methods [ sym ] ) return router . on ( route , methods ) assert . equal ( typeof methods , 'object' ) // mount http methods router . on ( route , function ( args ) { demuxSsa ( args , function ( req , res , params ) { const meth = methodist ( req , defaultFn , methods ) meth ( req , res , params ) // default function to call if methods don't match // null -> null function defaultFn ( ) { router . _default ( args ) } } ) } ) return emit } }
wrap req, res, wayfarer to create new server obj -> obj
wrap req res wayfarer to create new server obj - > obj