{"id":10021209,"date":"2026-01-25T11:45:39","date_gmt":"2026-01-25T03:45:39","guid":{"rendered":"https:\/\/itmax.cn\/?p=10021209"},"modified":"2026-01-25T11:45:39","modified_gmt":"2026-01-25T03:45:39","slug":"hono-%e8%b7%af%e7%94%b1%e5%99%a8%e4%b8%ba%e4%bb%80%e4%b9%88%e8%bf%99%e4%b9%88%e5%bf%ab%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10021209","title":{"rendered":"Hono \u8def\u7531\u5668\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u5feb\uff1f"},"content":{"rendered":"<blockquote><p>\u4ece\u5e95\u5c42\u5f15\u64ce\u4f18\u5316\u89d2\u5ea6\uff0c\u6df1\u5165\u5256\u6790 Hono \u8def\u7531\u5668\u7684\u6781\u81f4\u6027\u80fd\u5965\u79d8<\/p><\/blockquote>\n<hr>\n<h2>\u5f15\u8a00<\/h2>\n<p>\u5728\u4f17\u591a JavaScript Web \u6846\u67b6\u4e2d\uff0cHono \u4ee5\u5176\u6781\u81f4\u7684\u6027\u80fd\u8868\u73b0\u8131\u9896\u800c\u51fa\u3002\u7279\u522b\u662f\u5728 <strong>Cloudflare Workers\u3001Deno \u7b49\u8fb9\u7f18\u8ba1\u7b97\u73af\u5883<\/strong>\u4e2d\uff0cHono \u7684\u8def\u7531\u5339\u914d\u901f\u5ea6\u5728\u540c\u7c7b\u6846\u67b6\u4e2d\u540d\u5217\u524d\u8305\u3002\u8fd9\u80cc\u540e\u7684\u79d8\u5bc6\u662f\u4ec0\u4e48\uff1f\u7b54\u6848\u5c31\u85cf\u5728\u5b83\u7684 <strong>RegExpRouter<\/strong> \u5b9e\u73b0\u4e2d\u3002<\/p>\n<blockquote><p><strong>\u26a0\ufe0f \u91cd\u8981\u63d0\u793a<\/strong>\uff1a\u672c\u6587\u91cd\u70b9\u8ba8\u8bba RegExpRouter \u7684\u6838\u5fc3\u539f\u7406\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0cHono \u4f7f\u7528 SmartRouter \u81ea\u52a8\u7ec4\u5408\u591a\u79cd\u8def\u7531\u5668\uff08RegExpRouter\u3001TrieRouter\u3001LinearRouter\uff09\u4ee5\u8fbe\u5230\u6700\u4f73\u6027\u80fd\u3002<\/p><\/blockquote>\n<p>\u672c\u6587\u5c06\u901a\u8fc7\u4e00\u4e2a\u7cbe\u7b80\u7684\u5b9e\u73b0\uff0c\u6df1\u5165\u5256\u6790 Hono \u8def\u7531\u5668\u7684\u6838\u5fc3\u539f\u7406\uff0c\u5e2e\u52a9\u4f60\u7406\u89e3\uff1a<\/p>\n<ul>\n<li>\u4e3a\u4ec0\u4e48 RegExp \u8def\u7531\u6bd4\u4f20\u7edf\u8def\u7531\u5feb<\/li>\n<li>\u8def\u7531\u662f\u5982\u4f55\u9884\u7f16\u8bd1\u7684<\/li>\n<li>\u53c2\u6570\u63d0\u53d6\u7684\u5de7\u5999\u8bbe\u8ba1<\/li>\n<\/ul>\n<hr>\n<p><strong>\ud83d\udccc \u5173\u952e\u8981\u70b9<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>\u9879\u76ee<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u6838\u5fc3\u539f\u7406<\/td>\n<td>\u5c06\u8def\u7531\u9884\u7f16\u8bd1\u4e3a\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u5229\u7528\u5f15\u64ce\u5e95\u5c42\u4f18\u5316<\/td>\n<\/tr>\n<tr>\n<td>\u6027\u80fd\u4f18\u52bf<\/td>\n<td>\u51cf\u5c11 JS \u5c42\u5f00\u9500\uff0c\u4e00\u6b21\u539f\u751f\u8c03\u7528\u5b8c\u6210\u5339\u914d<\/td>\n<\/tr>\n<tr>\n<td>\u6700\u4f73\u73af\u5883<\/td>\n<td>Cloudflare Workers\u3001Deno \u7b49\u8fb9\u7f18\u8ba1\u7b97\u5e73\u53f0<\/td>\n<\/tr>\n<tr>\n<td>\u5b9e\u9645\u67b6\u6784<\/td>\n<td>SmartRouter + RegExpRouter + TrieRouter \u7ec4\u5408<\/td>\n<\/tr>\n<tr>\n<td>\u6743\u8861\u8003\u8651<\/td>\n<td>Node.js \u73af\u5883\u6027\u80fd\u6253\u6298\u6263\uff0c\u8def\u7531\u6ce8\u518c\u8f83\u6162<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u4f20\u7edf\u8def\u7531\u7684\u6027\u80fd\u74f6\u9888<\/h2>\n<p>\u5728\u7406\u89e3 Hono \u7684\u4f18\u5316\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u770b\u770b\u4f20\u7edf\u8def\u7531\u7684\u5904\u7406\u65b9\u5f0f\uff1a<\/p>\n<pre><code class=\"javascript\">\/\/ \u4f20\u7edf\u8def\u7531\u7684\u5178\u578b\u5b9e\u73b0\nfunction matchRoute(path, routes) {\n  for (const route of routes) {\n    \/\/ 1. \u5b57\u7b26\u4e32\u5206\u5272\n    const pathParts = path.split('\/');\n    const routeParts = route.path.split('\/');\n\n    \/\/ 2. \u9010\u6bb5\u6bd4\u8f83\n    if (pathParts.length !== routeParts.length) continue;\n\n    const params = {};\n    let matched = true;\n\n    \/\/ 3. JS \u5c42\u9762\u7684\u5faa\u73af\u548c\u6761\u4ef6\u5224\u65ad\n    for (let i = 0; i &lt; pathParts.length; i++) {\n      if (routeParts[i].startsWith(':')) {\n        params[routeParts[i].slice(1)] = pathParts[i];\n      } else if (pathParts[i] !== routeParts[i]) {\n        matched = false;\n        break;\n      }\n    }\n\n    if (matched) return { route, params };\n  }\n  return null;\n}<\/code><\/pre>\n<p><strong>\u6027\u80fd\u95ee\u9898\u5728\u54ea\u91cc\uff1f<\/strong><\/p>\n<ul>\n<li>\u274c \u5927\u91cf\u7684\u5b57\u7b26\u4e32\u64cd\u4f5c\uff08<code>split<\/code>\u3001<code>slice<\/code>\uff09<\/li>\n<li>\u274c \u591a\u5c42\u5faa\u73af\u548c\u6761\u4ef6\u5224\u65ad\uff0c\u5168\u5728 JavaScript \u5c42\u9762\u6267\u884c<\/li>\n<li>\u274c \u6bcf\u4e2a\u8bf7\u6c42\u90fd\u8981\u91cd\u590d\u8fd9\u4e9b\u64cd\u4f5c<\/li>\n<\/ul>\n<h2>Hono \u7684\u89e3\u51b3\u65b9\u6848\uff1a\u4e0b\u6c89\u5230\u5f15\u64ce\u5c42<\/h2>\n<p>Hono \u7684\u6838\u5fc3\u601d\u60f3\u975e\u5e38\u7b80\u5355\u5374\u6781\u5176\u5de7\u5999\uff1a<\/p>\n<blockquote><p><strong>\u5c06\u8def\u7531\u5339\u914d\u903b\u8f91\u4ece JavaScript \u5c42\u4e0b\u6c89\u5230 JavaScript \u5f15\u64ce\u5e95\u5c42\uff08C++ \u5b9e\u73b0\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u5f15\u64ce\uff09<\/strong><\/p><\/blockquote>\n<h3>1. \u9884\u7f16\u8bd1\u9636\u6bb5\uff08\u5e94\u7528\u542f\u52a8\u65f6\uff09<\/h3>\n<p>\u5728\u5e94\u7528\u542f\u52a8\u65f6\uff0cHono \u4f1a\u5c06\u8def\u7531\u8def\u5f84\u8f6c\u6362\u4e3a\u6b63\u5219\u8868\u8fbe\u5f0f\uff1a<\/p>\n<pre><code class=\"typescript\">\/\/ \u8def\u7531\u8def\u5f84\uff1a\/user\/:id\/posts\/:postId\n\/\/ \u8f6c\u6362\u4e3a\u6b63\u5219\uff1a\/^\/\/user\/\/([^\/]+)\/\/posts\/\/([^\/]+)$\/\n\nconst paramNames: string[] = [];\n\nconst regexPath = path.replace(\/:([a-zA-Z0-9_]+)\/g, (_, paramName) =&gt; {\n  paramNames.push(paramName); \/\/ \u8bb0\u5f55\u53c2\u6570\u540d\n  return '([^\/]+)';           \/\/ \u66ff\u6362\u4e3a\u6355\u83b7\u7ec4\n});\n\nconst pattern = new RegExp(`^${regexPath}$`);<\/code><\/pre>\n<p><strong>\u5173\u952e\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li><code>:id<\/code> \u2192 <code>([^\/]+)<\/code>\uff1a\u5339\u914d\u9664 <code>\/<\/code> \u5916\u7684\u4efb\u610f\u5b57\u7b26<\/li>\n<li>\u53c2\u6570\u540d\u88ab\u4fdd\u5b58\u5728 <code>paramNames<\/code> \u6570\u7ec4\u4e2d<\/li>\n<li>\u8fd9\u4e2a&#8221;\u6602\u8d35&#8221;\u7684\u7f16\u8bd1\u8fc7\u7a0b\u53ea\u5728\u542f\u52a8\u65f6\u6267\u884c\u4e00\u6b21<\/li>\n<\/ul>\n<h3>2. \u5339\u914d\u9636\u6bb5\uff08\u8bf7\u6c42\u5230\u6765\u65f6\uff09<\/h3>\n<p>\u5f53\u8bf7\u6c42\u5230\u6765\u65f6\uff0c\u53ea\u9700\u8981\u4e00\u884c\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"typescript\">const match = pattern.exec(path);<\/code><\/pre>\n<p><strong>\u8fd9\u884c\u4ee3\u7801\u7684\u9b54\u6cd5\uff1a<\/strong><\/p>\n<ul>\n<li>\u2705 <code>exec<\/code> \u662f JavaScript \u5f15\u64ce\u7684\u539f\u751f\u65b9\u6cd5\uff0c\u7531 C++ \u5b9e\u73b0<\/li>\n<li>\u2705 \u6b63\u5219\u5f15\u64ce\u5728\u5e95\u5c42\u8fdb\u884c\u4e86\u9ad8\u5ea6\u4f18\u5316\uff08\u72b6\u6001\u673a\u3001JIT \u7f16\u8bd1\u7b49\uff09<\/li>\n<li>\u2705 \u65e0\u9700\u624b\u52a8\u5206\u5272\u5b57\u7b26\u4e32\u3001\u65e0\u9700 JS \u5c42\u5faa\u73af<\/li>\n<li>\u2705 \u53c2\u6570\u63d0\u53d6\u901a\u8fc7\u6355\u83b7\u7ec4\u81ea\u52a8\u5b8c\u6210<\/li>\n<\/ul>\n<h3>3. \u53c2\u6570\u63d0\u53d6<\/h3>\n<p>\u5339\u914d\u6210\u529f\u540e\uff0c\u53c2\u6570\u63d0\u53d6\u4e5f\u975e\u5e38\u7b80\u6d01\uff1a<\/p>\n<pre><code class=\"typescript\">const params: Record&lt;string, string&gt; = {};\nroute.paramNames.forEach((name, index) =&gt; {\n  params[name] = match[index + 1]; \/\/ match[0] \u662f\u5b8c\u6574\u5339\u914d\n});<\/code><\/pre>\n<h2>\u5b8c\u6574\u5b9e\u73b0\u89e3\u6790<\/h2>\n<p>\u8ba9\u6211\u4eec\u770b\u5b8c\u6574\u7684\u7b80\u5316\u5b9e\u73b0\uff0c\u5305\u542b\u6240\u6709\u5fc5\u8981\u7684\u7c7b\u578b\u5b9a\u4e49\uff1a<\/p>\n<pre><code class=\"typescript\">\/\/ ============ \u7c7b\u578b\u5b9a\u4e49 ============\n\n\/**\n * \u8def\u7531\u5904\u7406\u51fd\u6570\u7c7b\u578b\n * @param params - \u4ece URL \u4e2d\u63d0\u53d6\u7684\u53c2\u6570\u5bf9\u8c61\n *\/\ntype Handler = (params: Record&lt;string, string&gt;) =&gt; void;\n\n\/**\n * \u8def\u7531\u4fe1\u606f\u63a5\u53e3\n *\/\ninterface Route {\n  method: string;        \/\/ HTTP \u65b9\u6cd5\uff08GET, POST, etc.\uff09\n  path: string;          \/\/ \u539f\u59cb\u8def\u5f84\u6a21\u5f0f\uff08\u5982 \/user\/:id\uff09\n  handler: Handler;      \/\/ \u8def\u7531\u5904\u7406\u51fd\u6570\n  paramNames: string[];  \/\/ \u53c2\u6570\u540d\u6570\u7ec4\uff08\u5982 ['id', 'postId']\uff09\n}\n\n\/**\n * \u5339\u914d\u7ed3\u679c\u63a5\u53e3\n *\/\ninterface MatchResult {\n  handler: Handler;\n  params: Record&lt;string, string&gt;;\n}\n\n\/\/ ============ \u6838\u5fc3\u8def\u7531\u5668\u5b9e\u73b0 ============\n\nexport class DemoRegExpRouter {\n  \/\/ \u5b58\u50a8\u9884\u7f16\u8bd1\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u548c\u8def\u7531\u4fe1\u606f\n  private routes: { pattern: RegExp; route: Route }[] = [];\n\n  \/\/ \u6ce8\u518c\u8def\u7531\uff1a\u9884\u7f16\u8bd1\n  add(method: string, path: string, handler: Handler) {\n    const paramNames: string[] = [];\n\n    \/\/ \u5c06 :param \u8f6c\u4e3a\u6b63\u5219\u6355\u83b7\u7ec4\n    const regexPath = path.replace(\/:([a-zA-Z0-9_]+)\/g, (_, paramName) =&gt; {\n      paramNames.push(paramName);\n      return '([^\/]+)';\n    });\n\n    const pattern = new RegExp(`^${regexPath}$`);\n    this.routes.push({ pattern, route: { method, path, handler, paramNames } });\n  }\n\n  \/\/ \u5339\u914d\u8def\u7531\uff1a\u6267\u884c\u6b63\u5219\n  match(method: string, path: string) {\n    for (const { pattern, route } of this.routes) {\n      if (route.method !== method &amp;&amp; route.method !== 'ALL') continue;\n\n      const match = pattern.exec(path); \/\/ \u6838\u5fc3\uff1a\u539f\u751f\u6b63\u5219\u5339\u914d\n\n      if (match) {\n        const params: Record&lt;string, string&gt; = {};\n        route.paramNames.forEach((name, index) =&gt; {\n          params[name] = match[index + 1];\n        });\n        return { handler: route.handler, params };\n      }\n    }\n    return null;\n  }\n}<\/code><\/pre>\n<h2>\u5b9e\u6218\u793a\u4f8b<\/h2>\n<pre><code class=\"typescript\">const router = new DemoRegExpRouter();\n\n\/\/ \u6ce8\u518c\u8def\u7531\nrouter.add('GET', '\/user\/:id', (params) =&gt; {\n  console.log(`\u83b7\u53d6\u7528\u6237\u8be6\u60c5\uff0cID: ${params.id}`);\n});\n\nrouter.add('GET', '\/user\/:id\/posts\/:postId', (params) =&gt; {\n  console.log(`\u83b7\u53d6\u7528\u6237 ${params.id} \u7684\u6587\u7ae0 ${params.postId}`);\n});\n\n\/\/ \u5339\u914d\u8bf7\u6c42\nconst result = router.match('GET', '\/user\/123\/posts\/456');\nif (result) {\n  result.handler(result.params);\n  \/\/ \u8f93\u51fa: \u83b7\u53d6\u7528\u6237 123 \u7684\u6587\u7ae0 456\n}<\/code><\/pre>\n<h2>\u6027\u80fd\u4f18\u52bf\u5206\u6790<\/h2>\n<p><strong>\u4e3a\u4ec0\u4e48 RegExpRouter \u66f4\u5feb\uff1f<\/strong><\/p>\n<ol>\n<li><strong>\u51cf\u5c11 JS \u6267\u884c\u5f00\u9500<\/strong>\uff1a\u4ece\u591a\u5c42\u5faa\u73af\u964d\u5230\u4e00\u6b21\u539f\u751f\u8c03\u7528<\/li>\n<li><strong>\u5f15\u64ce\u4f18\u5316<\/strong>\uff1a\u6b63\u5219\u5f15\u64ce\u7ecf\u8fc7\u6570\u5341\u5e74\u4f18\u5316\uff0c\u5305\u542b JIT\u3001\u72b6\u6001\u673a\u7b49\u6280\u672f<\/li>\n<li><strong>\u51cf\u5c11\u5185\u5b58\u5206\u914d<\/strong>\uff1a\u65e0\u9700\u9891\u7e41\u521b\u5efa\u6570\u7ec4\u3001\u5bf9\u8c61<\/li>\n<li><strong>\u4e00\u6b21\u6027\u7f16\u8bd1<\/strong>\uff1a\u9884\u7f16\u8bd1\u9636\u6bb5\u5b8c\u6210\u6240\u6709\u51c6\u5907\u5de5\u4f5c\uff0c\u8bf7\u6c42\u65f6\u96f6\u989d\u5916\u5f00\u9500<\/li>\n<\/ol>\n<p><strong>\u6027\u80fd\u5bf9\u6bd4\u6982\u89c8<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>\u65b9\u6848<\/th>\n<th>\u5b9e\u73b0\u5c42\u6b21<\/th>\n<th>\u6267\u884c\u6548\u7387<\/th>\n<th>\u9002\u7528\u573a\u666f<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u4f20\u7edf\u8def\u7531<\/td>\n<td>JavaScript \u5c42<\/td>\n<td>\u4e2d\u7b49<\/td>\n<td>\u901a\u7528\u573a\u666f<\/td>\n<\/tr>\n<tr>\n<td>RegExpRouter<\/td>\n<td>\u5f15\u64ce\u5e95\u5c42<\/td>\n<td>\u6781\u5feb<\/td>\n<td>\u8fb9\u7f18\u8ba1\u7b97\u3001\u9ad8\u5e76\u53d1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<blockquote><p><strong>\ud83d\udcca \u5b9e\u9645 Benchmark<\/strong>\uff1a\u6839\u636e <a href=\"https:\/\/link.segmentfault.com\/?enc=3wIDsJ7RSsQ81roU5PuvEg%3D%3D.c7ZOJotVsviRkGxUuCKiXAmFz7iCBawxiWbmbKxJiLgpoXNmDp%2FyojhCBAo9xiSG\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Hono \u5b98\u65b9\u6d4b\u8bd5<\/a>\uff0c\u5728 Cloudflare Workers \u548c Deno \u73af\u5883\u4e2d\uff0cHono \u662f\u540c\u7c7b\u6846\u67b6\u4e2d\u6700\u5feb\u7684\u3002\u4f46\u5728 Node.js \u73af\u5883\u4e2d\uff0c\u7531\u4e8e\u9002\u914d\u5668\u5f00\u9500\uff0c\u6027\u80fd\u4f18\u52bf\u4f1a\u6253\u6298\u6263\u3002<\/p><\/blockquote>\n<h2>Hono \u771f\u5b9e\u5b9e\u73b0\u7684\u8fdb\u4e00\u6b65\u4f18\u5316<\/h2>\n<p>\u672c\u6587\u7684\u7b80\u5316\u7248\u6bcf\u4e2a\u8def\u7531\u90fd\u662f\u72ec\u7acb\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u3002\u800c Hono \u7684\u771f\u5b9e\u5b9e\u73b0\u91c7\u7528\u4e86<strong>\u591a\u8def\u7531\u5668\u534f\u540c<\/strong>\u7684\u7b56\u7565\uff1a<\/p>\n<h3>1. SmartRouter\uff08\u667a\u80fd\u8def\u7531\u5668\uff09<\/h3>\n<p>Hono \u9ed8\u8ba4\u4f7f\u7528 <strong>SmartRouter<\/strong>\uff0c\u5b83\u4f1a\uff1a<\/p>\n<ul>\n<li>\u6839\u636e\u8def\u7531\u7279\u5f81\u81ea\u52a8\u9009\u62e9\u6700\u5feb\u7684\u8def\u7531\u5668<\/li>\n<li>\u52a8\u6001\u7ec4\u5408 RegExpRouter\u3001TrieRouter\u3001LinearRouter<\/li>\n<li>\u68c0\u6d4b\u8def\u7531\u6a21\u5f0f\u5e76\u6301\u7eed\u4f7f\u7528\u6700\u4f18\u65b9\u6848<\/li>\n<\/ul>\n<h3>2. \u8def\u7531\u5668\u5206\u5de5<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u8def\u7531\u5668<\/th>\n<th>\u9002\u7528\u573a\u666f<\/th>\n<th>\u7279\u70b9<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>RegExpRouter<\/strong><\/td>\n<td>\u52a8\u6001\u53c2\u6570\u8def\u7531<\/td>\n<td>\u6700\u5feb\uff0c\u4f46\u4e0d\u652f\u6301\u6240\u6709\u6a21\u5f0f<\/td>\n<\/tr>\n<tr>\n<td><strong>TrieRouter<\/strong><\/td>\n<td>\u590d\u6742\u8def\u7531\u6a21\u5f0f<\/td>\n<td>\u652f\u6301\u6240\u6709\u6a21\u5f0f\uff0c\u6027\u80fd\u4f18\u79c0<\/td>\n<\/tr>\n<tr>\n<td><strong>LinearRouter<\/strong><\/td>\n<td>\u5c11\u91cf\u8def\u7531<\/td>\n<td>\u7b80\u5355\u53ef\u9760\uff0c\u8def\u7531\u5c11\u65f6\u591f\u7528<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>3. \u5b9e\u9645\u4f18\u5316\u7b56\u7565<\/h3>\n<ul>\n<li><strong>\u9759\u6001\u8def\u7531\u4f18\u5148<\/strong>\uff1a<code>\/about<\/code>\u3001<code>\/contact<\/code> \u7b49\u4f7f\u7528 Map \u5feb\u901f\u67e5\u627e<\/li>\n<li><strong>\u8def\u7531\u9884\u5206\u7ec4<\/strong>\uff1a\u6309 HTTP \u65b9\u6cd5\u5206\u7ec4\uff0c\u51cf\u5c11\u5339\u914d\u6b21\u6570<\/li>\n<li><strong>\u5ef6\u8fdf\u7f16\u8bd1<\/strong>\uff1aRegExpRouter \u7f16\u8bd1\u8f83\u6162\uff0c\u9002\u5408\u5e94\u7528\u542f\u52a8\u65f6\u521d\u59cb\u5316\uff0c\u4e0d\u9002\u5408\u65e0\u670d\u52a1\u5668\u73af\u5883\u7684\u51b7\u542f\u52a8<\/li>\n<\/ul>\n<p>\u8fd9\u4e9b\u4f18\u5316\u4f7f\u5f97 Hono \u5728\u5904\u7406\u6570\u767e\u4e2a\u8def\u7531\u65f6\u4ecd\u7136\u4fdd\u6301\u6781\u9ad8\u6027\u80fd\u3002<\/p>\n<h2>\u5c40\u9650\u6027\u4e0e\u6743\u8861<\/h2>\n<p>RegExpRouter \u5e76\u975e\u94f6\u5f39\uff0c\u5728\u4f7f\u7528\u65f6\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u9650\u5236\uff1a<\/p>\n<h3>RegExpRouter \u7684\u5c40\u9650<\/h3>\n<ul>\n<li><strong>\u4e0d\u652f\u6301\u6240\u6709\u8def\u7531\u6a21\u5f0f<\/strong>\uff1a\u67d0\u4e9b\u590d\u6742\u7684\u8def\u7531\u89c4\u5219\u65e0\u6cd5\u7528\u7b80\u5355\u6b63\u5219\u8868\u793a<\/li>\n<li><strong>\u6ce8\u518c\u9636\u6bb5\u8f83\u6162<\/strong>\uff1a\u8def\u7531\u7f16\u8bd1\u9700\u8981\u65f6\u95f4\uff0c\u4e0d\u9002\u5408\u6bcf\u6b21\u8bf7\u6c42\u90fd\u91cd\u65b0\u521d\u59cb\u5316\u7684\u73af\u5883\uff08\u5982\u67d0\u4e9b\u65e0\u670d\u52a1\u5668\u51b7\u542f\u52a8\u573a\u666f\uff09<\/li>\n<li><strong>\u8c03\u8bd5\u96be\u5ea6<\/strong>\uff1a\u7f16\u8bd1\u540e\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u8bfb\u6027\u8f83\u5dee\uff0c\u51fa\u9519\u65f6\u96be\u4ee5\u5b9a\u4f4d<\/li>\n<li><strong>\u6a21\u5f0f\u7ea6\u675f<\/strong>\uff1a\u5982\u5e26\u4e25\u683c\u7ea6\u675f\u7684\u53c2\u6570 <code>\/:id(\/\/d+)<\/code> \u9700\u8981\u989d\u5916\u5904\u7406<\/li>\n<\/ul>\n<h3>\u8fd0\u884c\u73af\u5883\u5dee\u5f02<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u73af\u5883<\/th>\n<th>\u6027\u80fd\u8868\u73b0<\/th>\n<th>\u539f\u56e0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Cloudflare Workers<\/td>\n<td>\u2b50\u2b50\u2b50\u2b50\u2b50 \u6781\u5feb<\/td>\n<td>\u539f\u751f Web \u6807\u51c6 API<\/td>\n<\/tr>\n<tr>\n<td>Deno<\/td>\n<td>\u2b50\u2b50\u2b50\u2b50\u2b50 \u6781\u5feb<\/td>\n<td>\u539f\u751f Web \u6807\u51c6 API<\/td>\n<\/tr>\n<tr>\n<td>Bun<\/td>\n<td>\u2b50\u2b50\u2b50\u2b50 \u5f88\u5feb<\/td>\n<td>\u9ad8\u6027\u80fd JS \u8fd0\u884c\u65f6<\/td>\n<\/tr>\n<tr>\n<td>Node.js<\/td>\n<td>\u2b50\u2b50\u2b50 \u4e2d\u7b49<\/td>\n<td>\u9700\u8981\u9002\u914d\u5668\u8f6c\u6362<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<blockquote><p><strong>\ud83d\udca1 \u9009\u578b\u5efa\u8bae<\/strong>\uff1a\u5982\u679c\u4f60\u7684\u5e94\u7528\u8fd0\u884c\u5728\u8fb9\u7f18\u8ba1\u7b97\u73af\u5883\uff08Cloudflare Workers\u3001Vercel Edge Functions \u7b49\uff09\uff0cHono \u662f\u7edd\u4f73\u9009\u62e9\u3002\u5982\u679c\u662f\u4f20\u7edf Node.js \u670d\u52a1\u5668\uff0cFastify \u53ef\u80fd\u662f\u66f4\u597d\u7684\u9009\u62e9\u3002<\/p><\/blockquote>\n<p>\u4f46\u5bf9\u4e8e\u5927\u591a\u6570 Web \u5e94\u7528\u573a\u666f\uff0cRegExpRouter \u7684\u6027\u80fd\u4e0e\u529f\u80fd\u5e73\u8861\u5df2\u7ecf\u8db3\u591f\u4f18\u79c0\u3002<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>Hono \u7684 RegExpRouter \u901a\u8fc7&#8221;\u9884\u7f16\u8bd1 + \u5f15\u64ce\u4e0b\u6c89&#8221;\u7684\u7b56\u7565\uff0c\u5728\u7279\u5b9a\u73af\u5883\u4e2d\u5c06\u8def\u7531\u5339\u914d\u6027\u80fd\u63d0\u5347\u5230\u6781\u81f4\uff1a<\/p>\n<h3>\u6838\u5fc3\u4f18\u52bf<\/h3>\n<ol>\n<li><strong>\u9884\u7f16\u8bd1<\/strong>\uff1a\u542f\u52a8\u65f6\u4e00\u6b21\u6027\u5c06\u8def\u7531\u8f6c\u4e3a\u6b63\u5219\uff0c\u644a\u9500\u6210\u672c<\/li>\n<li><strong>\u5f15\u64ce\u4e0b\u6c89<\/strong>\uff1a\u5229\u7528 C++ \u5b9e\u73b0\u7684\u6b63\u5219\u5f15\u64ce\uff0c\u907f\u514d JS \u5c42\u5f00\u9500<\/li>\n<li><strong>\u53c2\u6570\u6355\u83b7<\/strong>\uff1a\u5de7\u5999\u5229\u7528\u6b63\u5219\u6355\u83b7\u7ec4\uff0c\u65e0\u9700\u624b\u52a8\u89e3\u6790<\/li>\n<li><strong>\u667a\u80fd\u7ec4\u5408<\/strong>\uff1aSmartRouter \u81ea\u52a8\u9009\u62e9\u6700\u4f18\u8def\u7531\u5668\uff0c\u517c\u987e\u6027\u80fd\u4e0e\u529f\u80fd<\/li>\n<\/ol>\n<h3>\u8bbe\u8ba1\u54f2\u5b66<\/h3>\n<p>\u8fd9\u79cd\u8bbe\u8ba1\u54f2\u5b66\u503c\u5f97\u6211\u4eec\u601d\u8003\uff1a<strong>\u6027\u80fd\u4f18\u5316\u7684\u7ec8\u6781\u76ee\u6807\uff0c\u5f80\u5f80\u662f\u8ba9&#8221;\u70ed\u8def\u5f84&#8221;\u4ee3\u7801\u5c3d\u53ef\u80fd\u591a\u5730\u8fd0\u884c\u5728\u66f4\u5e95\u5c42\u7684\u4f18\u5316\u73af\u5883\u4e2d<\/strong>\u3002<\/p>\n<p>\u5bf9\u4e8e Web \u6846\u67b6\u6765\u8bf4\uff0c\u8def\u7531\u5339\u914d\u5c31\u662f\u6700\u70ed\u7684\u8def\u5f84\u4e4b\u4e00\u3002Hono \u5728\u8fb9\u7f18\u8ba1\u7b97\u73af\u5883\u4e2d\u627e\u5230\u4e86\u8fd9\u4e2a\u95ee\u9898\u7684\u6700\u4f18\u89e3\uff0c\u540c\u65f6\u901a\u8fc7\u591a\u8def\u7531\u5668\u67b6\u6784\u4fdd\u8bc1\u4e86\u5e7f\u6cdb\u7684\u9002\u7528\u6027\u3002<\/p>\n<h3>\u6700\u4f73\u5b9e\u8df5<\/h3>\n<ul>\n<li>\u2705 <strong>\u8fb9\u7f18\u8ba1\u7b97\/Serverless<\/strong>\uff1aHono \u662f\u9996\u9009\uff08Cloudflare Workers\u3001Deno Deploy\uff09<\/li>\n<li>\u2705 <strong>\u9ad8\u5e76\u53d1\u573a\u666f<\/strong>\uff1a\u5145\u5206\u53d1\u6325 RegExpRouter \u6027\u80fd\u4f18\u52bf<\/li>\n<li>\u26a0\ufe0f <strong>Node.js \u73af\u5883<\/strong>\uff1a\u8003\u8651\u6027\u80fd\u6743\u8861\uff0c\u6216\u9009\u62e9 Fastify \u7b49\u4e13\u95e8\u4f18\u5316\u7684\u6846\u67b6<\/li>\n<li>\u26a0\ufe0f <strong>\u590d\u6742\u8def\u7531\u89c4\u5219<\/strong>\uff1a\u4e86\u89e3 RegExpRouter \u7684\u9650\u5236\uff0c\u5fc5\u8981\u65f6\u4f7f\u7528 TrieRouter<\/li>\n<\/ul>\n<hr>\n<p><strong>\u5ef6\u4f38\u9605\u8bfb\uff1a<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=TkthbjYwtP3RMxEJlplFtg%3D%3D.IU%2FJr%2FeP46oJs3Lp%2F67tpdtSro4AE6Du%2B5IW3vLIl6I%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Hono \u5b98\u65b9\u6587\u6863<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=yA6JwwOGqUiD9MhcMvh43w%3D%3D.5NUwW4EVMnE9NJke5Suy0zWB1tkjZW3ilqYo6cVVh5UA%2FkSIr2HWwPzmCsHYoAS9\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Hono Routers \u8be6\u89e3<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=LtvwZSE1hSvjN9BpO%2FI5Yg%3D%3D.5zMHmZKPKAebXLi2cckieqVzsTI%2B4aTfNR2pudNBKCKoChitqKsFFMMewyecENTZ\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Hono Benchmarks<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=CDCKuax2EQrky2A3dU9S%2Fg%3D%3D.rdha%2FTHWFJHelbtmjuodrMdJ2HqJTY1lc4yuIJYY4Ug%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">V8 \u6b63\u5219\u5f15\u64ce\u4f18\u5316\u6280\u672f<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=udQE690J8xb6iAD5FBoBKA%3D%3D.D7aJLp0Te0EkgquL%2BZ5IQYbwpVdx8jQRvTTVZOd4Xq%2F0zjPDF%2B%2FtMPW78NYRCZC%2F\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Web \u6846\u67b6\u6027\u80fd\u5bf9\u6bd4\u5de5\u5177<\/a><\/li>\n<\/ul>\n<p><strong>\u6280\u672f\u8d44\u6e90\uff1a<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=yzUuE2TzNhrnFSI24u1k1w%3D%3D.7aC2MaATO0bTZjEIeyVOjczYdmBJVTSZF56aQ2XGBX4%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Hono GitHub \u4ed3\u5e93<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=bletlAT6UbITLWUDdr3QUQ%3D%3D.%2FHAmMxlpp4dcjvOQIhbzwDZxFssbqcCB7xF2gsIbnJ0%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">RegExpRouter \u521b\u5efa\u8005\uff1aTaku Amano<\/a><\/li>\n<\/ul>\n<hr>\n<p><strong>\ud83d\udcdd \u6587\u7ae0\u8bf4\u660e<\/strong><\/p>\n<p>\u672c\u6587\u57fa\u4e8e\u5bf9 Hono \u6846\u67b6\u7684\u5b66\u4e60\u548c\u7814\u7a76\u7f16\u5199\uff0c\u4ee3\u7801\u793a\u4f8b\u4e3a\u7b80\u5316\u7248\u5b9e\u73b0\uff0c\u7528\u4e8e\u6559\u5b66\u76ee\u7684\u3002\u5b9e\u9645\u7684 Hono RegExpRouter \u5b9e\u73b0\u66f4\u52a0\u590d\u6742\u548c\u4f18\u5316\u3002<\/p>\n<p>\u6027\u80fd\u6570\u636e\u548c\u5bf9\u6bd4\u6765\u81ea Hono \u5b98\u65b9\u6587\u6863\u548c\u793e\u533a\u6d4b\u8bd5\uff0c\u5177\u4f53\u6570\u503c\u4f1a\u56e0\u6d4b\u8bd5\u73af\u5883\u3001\u8d1f\u8f7d\u7c7b\u578b\u3001\u8fd0\u884c\u65f6\u7248\u672c\u7b49\u56e0\u7d20\u800c\u5f02\u3002\u5b9e\u9645\u4f7f\u7528\u65f6\u8bf7\u6839\u636e\u81ea\u5df1\u7684\u573a\u666f\u8fdb\u884c\u6d4b\u8bd5\u3002<\/p>\n<p>\u5982\u679c\u60a8\u53d1\u73b0\u6587\u4e2d\u6709\u4efb\u4f55\u4e0d\u51c6\u786e\u4e4b\u5904\uff0c\u6b22\u8fce\u6307\u6b63\u3002<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000047570573\">https:\/\/segmentfault.com\/a\/1190000047570573<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ece\u5e95\u5c42\u5f15\u64ce\u4f18\u5316\u89d2\u5ea6\uff0c\u6df1\u5165\u5256\u6790 Hono \u8def\u7531\u5668\u7684\u6781\u81f4\u6027\u80fd\u5965\u79d8 \u5f15\u8a00 \u5728\u4f17\u591a JavaScript Web \u6846\u67b6 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10021209","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10021209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10021209"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10021209\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10021209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10021209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10021209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}