ZijianHe / koa-router

Router middleware for koa.
MIT License
4.85k stars 408 forks source link

Add _name to fix koa's built in debug #386

Open OmgImAlexis opened 6 years ago

OmgImAlexis commented 6 years ago

Without the _name field being set on the exported middleware Koa seems to use the exported generator/function's name. Since koa-router doesn't set this; Koa defaults back to dispatch for the middleware's name. Debugging docs.

I'd suggest either using koa-router or the name/url of the route if possible.

For example notice the 5 dispatch statements. That's caused by this.

app.use(tokenRoute.routes());
app.use(userRoute.routes());
app.use(queueRoute.routes());
app.use(blogRoute.routes());
  koa:application use compress +0ms
  koa:application use responseTime +3ms
  koa:application use logger +1ms
  koa:application use conditional +0ms
  koa:application use etag +1ms
  koa:application use helmet +2ms
  koa:application use noTrailingSlash +0ms
  koa:application use bodyParser +2ms
  koa:application use filter +0ms
  koa:application use - +1ms
  koa:application use dispatch +0ms
  koa:application use dispatch +0ms
  koa:application use dispatch +0ms
  koa:application use dispatch +1ms
  koa:application use dispatch +0ms
  koa:application use koa404Handler +0ms
jbielick commented 6 years ago

Are you interested in opening a PR with this work?

OmgImAlexis commented 6 years ago

@jbielick sure, I just need someone that's an admin here to tell me which name to use for the debug name.

jbielick commented 6 years ago

It looks like the other ones just remove the koa- prefix and use what's remaining as the name, should we use router?

YanLobat commented 6 years ago

@jbielick why do you ignore my PR? :(

OmgImAlexis commented 6 years ago

@YanLobat please don't hijack other issues. If you need someone's attention just tag them and wait.