koa-autowire
v1.1.4
Published
autowiring koa http endpoints and middlewares
Downloads
9
Maintainers
Readme
koa-autowire
Installation
npm install koa-autowire
or
yarn add koa-autowire
Configuration
you need to pass a config file or object which include the following named exports or keys:
const db = {
// should be your db instance which will be referenced in koa context object
}
const server = {
key: // your ssl private key,
cert: // your ssl certificate,
httpPort: 80, // on this port koa will accept http
httpsPort: 443 // on this port koa will accept https
}
const koa = {
middlewares: {
customName: {
package: '', // any koa middleware
options: [] // constructor options
}
}
}
const endpoints = {
customName: {
method: '', // route endpoint method --> post, get, put, delete
route: '', // route path
middlewares: [] // middleware functions that will be used
}
}
Usage
Start app
const config = require('./config.js')
const server = require('koa-autowire')
const app = server.autowire(config)
server.start(app);
Stop app
server.stop(app)