moa-router一個(gè)快速的 HTTP 路由器
一個(gè)快速的 HTTP 路由器,在內(nèi)部使用一個(gè)高性能的基數(shù)樹(shù)(Radix Tree )(又名緊湊前綴樹(shù)(Prefix Tree)),支持路由參數(shù),通配符,它是獨(dú)立的框架。
性能
$ autocannon 127.0.0.1:3000/test
QPS
moa-router(http) 28456
moa-router(koa) 17439.6
koa-router 12748.73
moa-router(express) 11779.1
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')
})評(píng)論
圖片
表情
