Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@chewbank/ioa-koa

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chewbank/ioa-koa

ioa.js & koa.js http组件

  • 9.8.8
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@ioa/koa

集成koa.js、路由及相关配套服务的http组件

Install

npm install @ioa/koa
const ioa = require('@chewbank/ioa');

ioa.app("./main");

路由

路由按作用域可分为全局路由、应用级路由、应用内路由三种,示例如下:

const { router } = require('@app')

router.global(cors); // 全局路由,跨应用,添加到所有path路由中间件之前

router.befor(token); // 应用级路由,中间件仅在当前应用内生效

router.get('/', "token", 'index.home'); // 应用内路由

router.get('/sms/:sid/sd/:id', 'index.sms');

router.post('/sms/:sid/sd/:sid', 'index.sms');

router.post('/login', 'index.login');

router.put('/login', 'index.login');

router.delele('/login', 'index.login');
声明式路由

声明式路由具有高度灵活和可定制url的特性。允许随意定义url格式,调用任意middleware、controller,但每个url都需要单独定义。

自动寻址路由

指定一个controller目录,路由解析器根据目录结构自动寻址,不再需要单独配置每个路由。这对于常规、标准化路由的定义非常方便,但是缺乏灵活性。

// 映射到controller/admin目录
router.controller('admin')
RESTful路由

RESTful路由与Controller的映射关系

MethodPathController.Action
GET/testindex
GET/test/:iddetails
POST/testcreate
PUT/test/:idupdate
DELETE/test/:iddestroy
// 自动生成get、post、put、delete
router.resources('/rest', 'rest')

中间件

在$app/middleware目录下添加中间件文件,框架自动载入并进行类型检测。

controller

支持Class、Object、箭头函数三种方式定义controller,不支持用普通函数直接定义controller(目前仅通过有无prototype来区分,所有包含prototype属性的函数均被视为构造函数)

在$app/controller目录下创建控制器文件,框架自动载入并进行类型检测,支持多级目录分组。

FAQs

Package last updated on 18 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc