npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ioa/koa

v20.0.0

Published

ioa.js & koa.js http组件

Downloads

24

Readme

@ioa/koa

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

Install

npm install @ioa/koa
// 根入口文件
import ioa from 'ioa';

ioa.apps("./main");
// 应用入口文件
import ioa from 'ioa';
const app = ioa.app();

app.component("@ioa/config");
app.component("@ioa/koa");

路由

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

import ioa from 'ioa';
const { router } = ioa.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的映射关系

Method | Path | Controller.Action --- | --- | ---: GET | /test | index GET | /test/:id | details POST | /test | create PUT | /test/:id | update DELETE | /test/:id | destroy

// 自动生成get、post、put、delete
router.resources('/rest', 'rest')

中间件

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

controller

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

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