Search code examples
node.jskoakoa2

How to NOT respond at all to a request using koa 2?


I want to implement a shadowban. Above a certain rate limit, I want to not respond anything to a request.

I couldn't find how to do that in the doc.

It seems setting body = null will still trigger a response.

How may I prevent koa@2 from answering to a request?


Solution

  • You should be able to do this by setting ctx.respond = false in your route handler.

    Having a look through koa's source code shows this: https://github.com/koajs/koa/blob/master/lib/application.js#L201

    function respond(ctx) {
      // allow bypassing koa
      if (false === ctx.respond) return;
      // ...