@kway/core

0.1.3 • Public • Published

@kway/core 使用说明

介绍

@kway/core是基于Koa、GraphQL搭建的服务程序

安装

目前属于实验阶段,npm i @kway/core

使用

import server from '@kway/core`

server.listen({
  models, // 数据处理模型程序
  auth, // 服务器请求验证方法
  handlers // 自定义Koa解决器
})

参数说明

models // 数据处理模型程序

如定义Test为数据处理模型则

import Test from './models/test`
{
  models: {test: Test}
}

请求验证方法 返回Boolean true-请求通过 false-请求被拒绝

{
  auth(request /*请求对象,等同于Koa的ctx.request对象*/){
    // 验证提交数据内容,如token或sessionid
    return true
  }
}

自定义Koa解决器

handlers: [
  async function (ctx, next) {
    if (ctx.path.indexOf('/test') > -1) {
      ctx.body = await 'foo'
    } else {
      await next()
    }
  }
]

Readme

Keywords

none

Package Sidebar

Install

npm i @kway/core

Weekly Downloads

2

Version

0.1.3

License

MIT

Unpacked Size

15.6 kB

Total Files

3

Last publish

Collaborators

  • kway