koa-micro
v1.2.0
Published
Koa 2 microservices with batteries included.
Downloads
24
Readme
koa-micro
Koa 2 microservices with batteries included.
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