Skip to content

Determine if route exists #95

@shennan

Description

@shennan

Is there a way of determining if an exact route exists and running some code if it doesn't. For example:

const Router = require('router')

const route = Router().use('/some/route', (res, req, next) => next())

route({url: '/some/nonexistent/route', method: 'get'}, {}, err => {
  if (err && err instanceof NoRouteError) {
    console.log('No route match')
  }
})

Or perhaps something like:

const Router = require('router')

const route = Router().use('/some/route', (res, req, next) => next())

const routeExists = route.test({url: '/some/nonexistent/route', method: 'get'})

console.log(routeExists ? 'ok' : 'No route match')

I'm currently using the library without any HTTP server, just as a router and middleware engine. So req.send() doesn't exist for me (and shouldn't), I simply call next() until there is no more middleware in the stack.

Any direction on this would be great.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions