🚀 Socket Launch Week Day 4:Socket MCP Adds Org Alerts, Threat Feed Review, and Package Inspection.Learn more
Sign In

@zenweb/router

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zenweb/router

Zenweb Router module

latest
npmnpm
Version
6.6.0
Version published
Maintainers
1
Created
Source

ZenWeb Router module

ZenWeb 所使用的路由模块

Install

npm i @zenweb/router
import { Core } from '@zenweb/core';
import router from '@zenweb/router';

const app = new Core();
app.setup(router());
app.start();


// GET: /
app.router.get('/', ctx => {
  ctx.body = 'static-index'; // static-index
});

// GET: /param/testval
app.router.get('/param/:name', ctx => {
  ctx.body = 'param value: ' + ctx.params.name; // param value: testval
});

// GET: /param/prefix99999suffix
app.router.get('/param/prefix:{name}suffix', ctx => {
  ctx.body = 'param value: ' + ctx.params.name; // param value: 99999
});

// GET: /param/with-regex/99999
app.router.get('/param/with-regex/:id(\\d+)', ctx => {
  ctx.body = 'param value: ' + ctx.params.id; // param value: 99999
});

// GET: /wildcardany/some/path
app.router.get('/wildcard*', ctx => {
  ctx.body = 'wildcard: ' + ctx.params.wildcard; // wildcard: any/some/path
});

// GET: /some/pathsuffix
app.router.get('*suffix', ctx => {
  ctx.body = 'wildcard: ' + ctx.params.wildcard; // wildcard: /some/path
});

// GET: /betweenany/valuesuffix
app.router.get('/between*suffix', ctx => {
  ctx.body = 'wildcard: ' + ctx.params.wildcard; // wildcard: any/value
});

// GET: /regex/aaa
app.router.get(/^\/regex\/(aaa|bbb)$/i, ctx => {
  ctx.body = 'regex: ' + ctx.params.$1; // regex: aaa
});

Benchmark

{ totalRootRouters: 6000, totalSubRouters: 0 } x 10000 times

Static | example: /test733

implementtotalms/reqfaster
koa-router59970.5997-
zen-router60.00061000x

Param | example: /param160/5dcc08b5-f702-4ae0-9dc3-264a5dcf187a

implementtotalms/reqfaster
koa-router64420.6442-
zen-router250.0025258x

Wildcard | example: /45d83a7a-491c-4481-80a5-77e112b563ab/491suffix

implementtotalms/reqfaster
koa-router64000.64-
zen-router2470.024726x

Regex | example: /regex746/31f0843d-329f-4d62-b354-166ffc78e6f0

implementtotalms/reqfaster
koa-router62520.6252-
zen-router8960.08967x

Random | static, param, regex, wildcard

implementtotalms/reqfaster
koa-router63760.6376-
zen-router3390.033919x

Not Found

implementtotalms/reqfaster
koa-router49690.4969-
zen-router7080.07087x

{ totalRootRouters: 6000, totalSubRouters: 12000 } x 10000 times

Static | example: /test287

implementtotalms/reqfaster
koa-router530925.3092-
zen-router6820.068278x

Param | example: /sub1/param149/e653d812-c1e0-4fc0-9769-386815c42d54

implementtotalms/reqfaster
koa-router547965.4796-
zen-router6940.069479x

Wildcard | example: /0dc74cd0-2f43-4cbe-80b0-ae0b81db78d1/395suffix

implementtotalms/reqfaster
koa-router466004.66-
zen-router6180.061875x

Regex | example: /regex721/77dfaf19-caad-4fb7-9ebe-8a9153265dd8

implementtotalms/reqfaster
koa-router551955.5195-
zen-router11750.117547x

Random | static, param, regex, wildcard

implementtotalms/reqfaster
koa-router471894.7189-
zen-router8680.086854x

Not Found

implementtotalms/reqfaster
koa-router460084.6008-
zen-router11410.114140x

Keywords

web

FAQs

Package last updated on 23 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts