@mhio/koa-web-handle

0.6.0 • Public • Published

@mhio/koa-handle | git | npm

A Koa Handler to do all the heavy lifting, so you just write logic

Install

yarn add @mhio/koa-web-handle
npm install @mhio/koa-web-handle

Usage

API docs

const Koa = require('koa')
const Router = require('koa-router')
const {KoaWebHandle} = require('@mhio/koa-web-handle')

let handler = {
  ok: ()=> Promise.resolve('<ok>ok</ok>'),
  template: ()=> Promise.resolve({ say: 'hello' }),
  error: ()=> Promise.reject(new Error('nope')),
}

const app = new Koa()
const router = new Router()

KoaHandle.views({ path: '../views', engine: 'mustache', extension: 'ms' })
app.use(KoaHandle.tracking()) // first for logging/timings
app.use(KoaHandle.error())

router.get('/ok', KoaHandle.response(handler, 'ok'))
router.post('/rendered', KoaHandle.response(handler, 'other', { template: 'helloer' }))
router.get('/error', KoaHandle.response(handler, 'error'))

app.use(router.routes())
   .use(router.allowedMethods())

app.use(KoaHandle.notFound())

app.listen()

Related

npm

@mhio/koa-api / @mhio/koa-api-handle

@mhio/koa-web / @mhio/koa-web-handle

Readme

Keywords

Package Sidebar

Install

npm i @mhio/koa-web-handle

Weekly Downloads

0

Version

0.6.0

License

MIT

Unpacked Size

49 kB

Total Files

14

Last publish

Collaborators

  • mhio