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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@fastcar/koa

v0.1.21

Published

fastcar框架下对koa的包装

Readme

基于封装koa的web成型框架

快速安装

npm install @fastcar/koa

基本原理

  • 采用@fastcar/core框架,然后将koa包装成一个基础组件进行调用
  • 加载顺序为优先加载自定义中间件->加载自定义路由->启动http服务进行监听
  • 停止阶段 延迟一秒左右 将server进行关闭

如何使用

import { FastCarApplication } from "@fastcar/core";
import { Application } from "@fastcar/core/annotation";
import { EnableKoa } from "@fastcar/koa/annotation";

@Application //注入基础框架
@EnableKoa //开启koa
class APP {
 app!: FastCarApplication;
}

export const app = new APP();

添加一个路由访问

import { Controller } from "@fastcar/core/annotation";
import { GET } from "@fastcar/koa/annotation";
import { Context } from "koa";


@Controller
export default class HelloController {

 @GET("/")
 home(params: string, ctx: Context) {
  console.log("这边请注意 params是params和body二合一的参数 重名的值会优先取body的");
  console.log('body取 ctx.request.body');
  console.log('路径后参数取ctx.params');
  return "hello world";
 }
}

如何引用koa中间件

//自定义中间件
//默认会出传入 app: FastCarApplication 可供选择
function Example(): koa.Middleware {
    return async (ctx: koa.Context, next: Function) => {
        console.log("example--- in");
        await next();
        console.log("example--- out");
    };
}

//在主入口内添加
import { FastCarApplication } from "@fastcar/core";
import { Application } from "@fastcar/core/annotation";
import { EnableKoa } from "@fastcar/koa/annotation";

@Application //注入基础框架
@EnableKoa //开启koa
@KoaMiddleware(Example)
class APP {
 app!: FastCarApplication;
}

export const app = new APP();

默认整合的koa中间件(开启方式为@KoaMiddleware(XX))

  • ExceptionGlobalHandler 用于koa运行时的异常情况捕捉
  • KoaBody 用于文件上传 与 koa-body的用法一致
  • KoaBodyParser 用于请求数据的解析 推荐客户端使用application/json的方式
  • KoaCors 跨域设置(后期可能会用更好的插件替代)
  • KoaStatic 整合了koa-static,koa-range,koa-mount用于静态文件访问,可设置别名
  • Swagger 用于展示api文档使用(后期支持自动化配置说明)

注解说明

  • EnableKoa 作用于应用 开启Koa组件

  • AllMapping,ALL 作用于controller层 支持GET POST等请求方式访问

  • GetMapping GET

  • PostMapping POST

  • DeleteMapping DELETE

  • PatchMapping PATCH

  • PutMapping PUT

  • RequestMapping REQUEST 作用于头部,用于追加url

  • KoaMiddleware 作用于应用 用于加载中间件 越在应用上面 优先级越高

更多用法

参考项目git地址 @fastcar/koa/test下的simple内

项目开源地址