All Projects → venables → koa-plus

venables / koa-plus

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

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to koa-plus

Koa Helmet
Important security headers for koa
Stars: ✭ 595 (+3400%)
Mutual labels:  koa, secure, secure-by-default
bookshelf-secure-password
A Bookshelf.js plugin for handling secure passwords
Stars: ✭ 24 (+41.18%)
Mutual labels:  secure, secure-by-default
Airship
Secure Content Management for the Modern Web - "The sky is only the beginning"
Stars: ✭ 422 (+2382.35%)
Mutual labels:  secure, secure-by-default
Random compat
PHP 5.x support for random_bytes() and random_int()
Stars: ✭ 7,950 (+46664.71%)
Mutual labels:  secure, secure-by-default
Koa Proxy
Proxy middleware for koa
Stars: ✭ 221 (+1200%)
Mutual labels:  koa
Blog Frontend Project
Web frontend code for my blogs, develop with Vue.
Stars: ✭ 206 (+1111.76%)
Mutual labels:  koa
Koa2 Boilerplate
[Deprecated] Minimal koa v2 boilerplate. 🤣
Stars: ✭ 196 (+1052.94%)
Mutual labels:  koa
Parrot Mocker Web
Simple web server to forward received requests to real servers or just mock
Stars: ✭ 194 (+1041.18%)
Mutual labels:  koa
teapot
Utilities for working with HTTP status codes, errors, and more
Stars: ✭ 14 (-17.65%)
Mutual labels:  koa
Atlas Of Thrones
An interactive "Game of Thrones" map powered by Leaflet, PostGIS, and Redis.
Stars: ✭ 253 (+1388.24%)
Mutual labels:  koa
Openapi Backend
Build, Validate, Route, Authenticate and Mock using OpenAPI
Stars: ✭ 216 (+1170.59%)
Mutual labels:  koa
Umajs
Umajs,easy-to-use framework base on Typescript
Stars: ✭ 209 (+1129.41%)
Mutual labels:  koa
Koa Websocket
Light wrapper around Koa providing a websocket middleware handler that is koa-route compatible.
Stars: ✭ 224 (+1217.65%)
Mutual labels:  koa
Maka
Maka.js是基于react的一个前端微服务开发框架(makajs.com)
Stars: ✭ 200 (+1076.47%)
Mutual labels:  koa
Javascript Boilerplate
Node.js+Koa.js+PostgreSQL+React.js+Webpack+Mocha+Makefile, a starter kit for new apps
Stars: ✭ 253 (+1388.24%)
Mutual labels:  koa
Egg Core
A core Pluggable framework based on koa.
Stars: ✭ 194 (+1041.18%)
Mutual labels:  koa
Koa Webpack Middleware
webpack dev&hot middleware for koa2
Stars: ✭ 215 (+1164.71%)
Mutual labels:  koa
Strapi Sdk Javascript
🔌 Official JavaScript SDK for APIs built with Strapi.
Stars: ✭ 247 (+1352.94%)
Mutual labels:  koa
Graphql Demo
🎉Koa + GraphQL + Apollo-Server demo
Stars: ✭ 215 (+1164.71%)
Mutual labels:  koa
Nuxt Juejin Project
仿掘金web网站,使用服务端渲染。主要技术:nuxt + koa + vuex + axios + element-ui 。
Stars: ✭ 209 (+1129.41%)
Mutual labels:  koa

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].