npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

koa-plus

v1.2.1

Published

The Koa framework extended for APIs. Optimized for security, scalability, and productivity

Downloads

23

Readme

koa-plus

Version Build Status Coverage Status Dependency Status Standard - JavaScript Style Guide Downloads

koa-plus is the koa framework (v2) extended for APIs. Optimized for security, scalability, and productivity.

Features

  • Important security headers via helmet.
  • CORS support via kcors.
  • Adds an X-Response-Time header to all responses.
  • Adds an X-Request-Id header to all requests as they come in for easier debugging.
    • Also passes through client/proxy/load-balancer generated X-Request-Id headers as X-Client-Request-Id
  • Uses koa-body to parse any request body type
  • Adds ETag headers to allow conditional GET requests (respond with 304 Not Modified)
  • Object stream support via koa-json
  • Request logging via koa-morgan
  • Simple ctx.debug (or ctx.app.debug) logging via the debug module
  • Pretty-printed JSON in development
  • Exposes the app configuration on ctx as ctx.config (or, app.context.config)

Each feature can be disabled individually.

Installation

Install koa-plus via yarn or npm:

yarn add koa-plus
npm install koa-plus --save

Usage

Existing apps:

Simply replace your existing koa require with koa-plus

Old:

const Koa = require('koa')
const app = new Koa()
// ...

New:

const Koa = require('koa-plus')
const app = new Koa()
// ...

Configuration

Some of the middleware included in koa-plus allows for options. To pass options to these middleware, simply pass the options to the constructor.

Options

  • body: Use the same options as the koa-body middleware accepts. Docs
  • compress: Use the same options as the koa-compress middleware accepts. Docs
  • cors: Use the same options as the kcors middleware accepts. Docs
  • debug: Set the name of the debug logger
  • helmet: Use the same options as the helmet middleware accepts. Docs
  • json: Use the same options as the koa-json middleware accepts. Docs
  • logger: Use format for the logger format, and the remaining options as what morgan accepts Docs

Example

const Koa = require('koa-plus')

const app = new Koa({
  body: {
    jsonLimit: '10kb' // Sets the json request body limit to 10k
  },
  compress: {
    threshold: 2048 // Sets the threshold to Gzip responses at 2k (2048 bytes)
  },
  cors: {
    origin: '*' // Set the `Access-Control-Allow-Origin` header to be `*`
  },
  debug: {
    name: 'worker' // Set the debug logger name
  },
  helmet: {
    noCache: true,  // Sets the `Cache-Control` headers to prevent caching
    frameguard: {
      action: 'deny' // Set the `X-Frame-Options' header to be `DENY`
    }
  },
  json: {
    pretty: false // Disables pretty-printing
  },
  logger: {
    format: 'dev' // Use the `dev` format of logging
  }
})

Disabling middleware

Each of the middleware in koa-plus can be disabled individually by using the enabled option.

As an example, to reset koa-plus back to basic koa functionality, use the following config:

const Koa = require('koa-plus')

const app = new Koa({
  body: {
    enabled: false
  },
  compress: {
    enabled: false
  },
  cors: {
    enabled: false
  },
  debug: {
    enabled: false
  },
  etag: {
    enabled: false
  },
  helmet: {
    enabled: false
  },
  json: {
    enabled: false
  },
  logger: {
    enabled: false
  },
  requestId: {
    enabled: false
  },
  responseTime: {
    enabled: false
  }
})

Testing

To run the tests locally, simply run

yarn test

or

npm test