微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

moa-router 安装使用 一个快速的 HTTP 路由器

程序名称:moa-router 安装使用

授权协议: MIT

操作系统: 跨平台

开发语言: JavaScript

moa-router 安装使用 介绍

一个快速的 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')
})

moa-router 安装使用 官网

https://github.com/moajs/moa-router

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐