Skip to content

transitive-bullshit/koa-micro

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

koa-micro

Koa 2 microservices with batteries included.

NPM Build Status JavaScript Style Guide

Installation

npm install --save koa-micro

This module uses async await and therefore requires node >= 8.

Usage

'use strict'

// ENV are set upstream at the container level
// we set them here only for demo purposes
process.env.APP_NAME = 'example-service'
process.env.REVISION = 'example-revision'

const config = require('config')
const micro = require('koa-micro')

const app = micro()

app.use(async (ctx, next) => {
  ctx.body = config
})

const port = process.env.PORT || 5000
const server = app.listen(port, () => {
  micro.logger.info(`${process.env.APP_NAME}:${process.env.REVISION} up @ http://localhost:${port}`)
})

process.on('SIGINT', () => server.close())

What's included

  • Koa 2 app
  • Context utility assertFound
  • Context utility assertParam
  • Context utility success
  • Logger supporting Google Cloud Trace
  • Error handler middleware with Google Cloud Errors
  • Access logs middleware
  • Response time middleware
  • CORS middleware
  • OPTIONS middleware
  • Gzip middleware
  • Health check endpoint (/alive by default)

Usage & Configuration

This module uses config leveraging the sub-module pattern. The base config is available at ./config and can be overridden upstream by the actual service by simply adding values to the upstream configuration.

The resulting config will be the merged result of Object.assign(micro-config, upstream-config).

License

MIT © Travis Fischer

Support my OSS work by following me on twitter twitter