moa-router 正在参加 2021 年度 OSC 中国开源项目评选,请投票支持!
moa-router 在 2021 年度 OSC 中国开源项目评选 中已获得 {{ projectVoteCount }} 票,请投票支持!
2021 年度 OSC 中国开源项目评选 正在火热进行中,快来投票支持你喜欢的开源项目!
2021 年度 OSC 中国开源项目评选 >>> 中场回顾
moa-router 获得 2021 年度 OSC 中国开源项目评选「最佳人气项目」 !
授权协议 MIT
开发语言 JavaScript
操作系统 跨平台
软件类型 开源软件
开源组织
地区 不详
投 递 者 周其
适用人群 未知
收录时间 2018-02-01

软件简介

一个快速的 HTTP 路由器,在内部使用一个高性能的基数树Radix Tree )(又名紧凑前缀树Prefix Tree)),支持路由参数,通配符,它是独立的框架。

性能

$ autocannon 127.0.0.1:3000/test

QPS

  1. moa-router(http) 28456

  2. moa-router(koa) 17439.6

  3. koa-router 12748.73

  4. moa-router(express) 11779.1

  5. express-router 10374.6

安装

$ npm i --save moa-router

使用

Koa

const http = require('http')
const Koa = require('koa');
const app = new Koa();

const router = require('moa-router')()

router.get('/', (ctx, next) => {
  ctx.body = {'path': 'root'}
})

router.on('GET', '/test', (ctx, next) => {
  ctx.body = {'hello': 'world'}
})

app.use(router.routes());

app.use(async function (ctx, next) {
  ctx.body = "default"
});

const server = http.createServer(app.callback())

server.listen(3030, err => {
  if (err) throw err
  console.log('Server listening on: http://localhost:3000')
})
展开阅读全文

代码

的 Gitee 指数为
超过 的项目

评论

点击引领话题📣 发布并加入讨论🔥
暂无内容
发表了博客
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
发表了问答
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
暂无内容
0 评论
1 收藏
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部