{"id":49152,"date":"2024-12-02T09:29:37","date_gmt":"2024-12-02T01:29:37","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49152\/"},"modified":"2024-12-02T09:29:37","modified_gmt":"2024-12-02T01:29:37","slug":"middleware-no-lithe-como-funciona-e-como-criar-o-seu-proprio","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/49152\/","title":{"rendered":"Middleware no Lithe: Como Funciona e Como Criar o Seu Pr\u00f3prio"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Middleware no Lithe: Como Funciona e Como Criar o Seu Pr\u00f3prio<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p><span style=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u5404\u4f4d\u5c0f\u4f19\u4f34\u4eec\uff0c\u5927\u5bb6\u597d\u5440\uff01\u770b\u770b\u4eca\u5929\u6211\u53c8\u7ed9\u5404\u4f4d\u5e26\u6765\u4e86\u4ec0\u4e48\u6587\u7ae0\uff1f\u672c\u6587\u6807\u9898<span style=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u662f<\/span><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aMiddleware no Lithe: Como Funciona e Como Criar o Seu Pr\u00f3prio\u300b<\/span>\uff0c\u5f88\u660e\u663e\u662f\u5173\u4e8e<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u7684\u6587\u7ae0\u54c8\u54c8\u54c8\uff0c\u5176\u4e2d\u5185\u5bb9\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u5982\u679c\u80fd\u5e2e\u5230\u4f60\uff0c\u89c9\u5f97\u5f88\u4e0d\u9519\u7684\u8bdd\uff0c\u6b22\u8fce\u5404\u4f4d\u591a\u591a\u70b9\u8bc4\u548c\u5206\u4eab\uff01<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241113\/173146845767341ca97401f.jpg\" class=\"aligncenter\" title=\"Middleware no Lithe: Como Funciona e Como Criar o Seu Pr\u00f3prio\u63d2\u56fe\" alt=\"Middleware no Lithe: Como Funciona e Como Criar o Seu Pr\u00f3prio\u63d2\u56fe\" \/><\/p>\n<p>\u4e2d\u95f4\u4ef6\u63d0\u4f9b\u4e86\u4e00\u79cd\u65b9\u4fbf\u7684\u673a\u5236\u6765\u68c0\u67e5\u548c\u8fc7\u6ee4\u8fdb\u5165\u5e94\u7528\u7a0b\u5e8f\u7684 http \u8bf7\u6c42\u3002\u4f8b\u5982\uff0clithe \u5305\u542b\u7528\u4e8e\u68c0\u67e5\u5e94\u7528\u7a0b\u5e8f\u7528\u6237\u662f\u5426\u7ecf\u8fc7\u8eab\u4efd\u9a8c\u8bc1\u7684\u4e2d\u95f4\u4ef6\u3002\u5982\u679c\u7528\u6237\u672a\u7ecf\u8fc7\u8eab\u4efd\u9a8c\u8bc1\uff0c\u4e2d\u95f4\u4ef6\u4f1a\u5c06\u7528\u6237\u91cd\u5b9a\u5411\u5230\u5e94\u7528\u7a0b\u5e8f\u7684\u767b\u5f55\u5c4f\u5e55\u3002\u4f46\u662f\uff0c\u5982\u679c\u7528\u6237\u7ecf\u8fc7\u8eab\u4efd\u9a8c\u8bc1\uff0c\u4e2d\u95f4\u4ef6\u5c06\u5141\u8bb8\u8bf7\u6c42\u5728\u5e94\u7528\u7a0b\u5e8f\u5185\u7ee7\u7eed\u8fdb\u884c\u3002<\/p>\n<hr>\n<h2> \u4e2d\u95f4\u4ef6\u5728 lithe \u4e2d\u7684\u5de5\u4f5c\u539f\u7406 <\/h2>\n<p>\u5728 lithe \u4e2d\uff0c\u4e2d\u95f4\u4ef6\u662f\u53ef\u4ee5\u8bbf\u95ee\u5e94\u7528\u7a0b\u5e8f\u8bf7\u6c42\u54cd\u5e94\u5faa\u73af\u4e2d\u7684\u8bf7\u6c42\u5bf9\u8c61 ($req)\u3001\u54cd\u5e94\u5bf9\u8c61 ($res) \u548c $next \u51fd\u6570\u7684\u51fd\u6570\u3002 $next \u51fd\u6570\u662f lithe \u8def\u7531\u5668\u4e2d\u7684\u4e00\u4e2a\u51fd\u6570\uff0c\u8c03\u7528\u65f6\u4f1a\u6267\u884c\u5f53\u524d\u4e2d\u95f4\u4ef6\u65c1\u8fb9\u7684\u4e2d\u95f4\u4ef6\u3002<\/p>\n<p>\u4e2d\u95f4\u4ef6\u51fd\u6570\u63d0\u4f9b\u4e86\u4e00\u79cd\u65b9\u4fbf\u7684\u673a\u5236\u6765\u68c0\u67e5\u3001\u8fc7\u6ee4\u548c\u5904\u7406\u8fdb\u5165\u5e94\u7528\u7a0b\u5e8f\u7684 http \u8bf7\u6c42\u3002<\/p>\n<p>\u4e2d\u95f4\u4ef6\u51fd\u6570\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b\u4efb\u52a1\uff1a<\/p>\n<ul>\n<li>\u8fd0\u884c\u4efb\u4f55\u4ee3\u7801\u3002<\/li>\n<li>\u66f4\u6539\u8bf7\u6c42\u548c\u54cd\u5e94\u5bf9\u8c61\u3002<\/li>\n<li>\u7ed3\u675f\u8bf7\u6c42-\u54cd\u5e94\u5468\u671f\u3002<\/li>\n<li>\u8c03\u7528\u5806\u6808\u4e2d\u7684\u4e0b\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u3002<\/li>\n<\/ul>\n<p>\u5982\u679c\u5f53\u524d\u4e2d\u95f4\u4ef6\u51fd\u6570\u6ca1\u6709\u7ed3\u675f\u8bf7\u6c42-\u54cd\u5e94\u5468\u671f\uff0c\u5219\u5fc5\u987b\u8c03\u7528 $next() \u5c06\u63a7\u5236\u6743\u4f20\u9012\u7ed9\u4e0b\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u51fd\u6570\u3002\u5426\u5219\uff0c\u8bf7\u6c42\u5c06\u88ab\u7b49\u5f85\u5904\u7406\u3002<\/p>\n<hr>\n<h2> \u4e2d\u95f4\u4ef6\u529f\u80fd\u7684\u5143\u7d20 <\/h2>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u663e\u793a\u4e86\u4e2d\u95f4\u4ef6\u51fd\u6570\u8c03\u7528\u7684\u5143\u7d20\uff1a<\/p>\n<pre>$app-&gt;use(function ($req, $res, $next) {\n    $next();\n});\n<\/pre>\n<p>\u5730\u70b9\uff1a<br \/> &#8211; $req\uff1a\u4e2d\u95f4\u4ef6\u51fd\u6570\u7684 http \u8bf7\u6c42\u53c2\u6570\uff0c\u6309\u7167\u60ef\u4f8b\u79f0\u4e3a\u201c$req\u201d\u3002<br \/> &#8211; $res\uff1a\u4e2d\u95f4\u4ef6\u51fd\u6570\u7684 http \u54cd\u5e94\u53c2\u6570\uff0c\u6309\u7167\u60ef\u4f8b\u79f0\u4e3a\u201c$res\u201d\u3002<br \/> &#8211; $next\uff1a\u4e2d\u95f4\u4ef6\u51fd\u6570\u7684\u56de\u8c03\u53c2\u6570\uff0c\u6309\u7167\u60ef\u4f8b\u79f0\u4e3a\u201c$next\u201d\u3002<\/p>\n<hr>\n<h2> \u5b9a\u4e49\u4e2d\u95f4\u4ef6 <\/h2>\n<p>\u8ba9\u6211\u4eec\u4ece\u4e00\u4e2a\u540d\u4e3a mylogger \u7684\u7b80\u5355\u4e2d\u95f4\u4ef6\u793a\u4f8b\u5f00\u59cb\u3002\u6bcf\u6b21\u8bf7\u6c42\u901a\u8fc7\u8be5\u4e2d\u95f4\u4ef6\u65f6\uff0c\u8be5\u4e2d\u95f4\u4ef6\u90fd\u4f1a\u6253\u5370 logged \u6d88\u606f\u3002\u4e2d\u95f4\u4ef6\u88ab\u5b9a\u4e49\u4e3a\u5206\u914d\u7ed9\u540d\u4e3a mylogger \u7684\u53d8\u91cf\u7684\u51fd\u6570\uff1a<\/p>\n<pre>$mylogger = function ($req, $res, $next) {\n  echo 'logged';\n  $next();\n};\n<\/pre>\n<p>\u6ce8\u610f\u4e0a\u9762\u5bf9 $next() \u7684\u8c03\u7528\u3002\u8c03\u7528\u6b64\u51fd\u6570\u4f1a\u8c03\u7528\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u4e0b\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u51fd\u6570\u3002 $next() \u51fd\u6570\u4e0d\u662f php \u6216 lithe \u7684\u4e00\u90e8\u5206\uff0c\u4f46\u5b83\u662f\u4f20\u9012\u7ed9\u4e2d\u95f4\u4ef6\u51fd\u6570\u7684\u7b2c\u4e09\u4e2a\u53c2\u6570\u3002 $next() \u51fd\u6570\u53ef\u4ee5\u6709\u4efb\u4f55\u540d\u79f0\uff0c\u4f46\u6309\u7167\u60ef\u4f8b\uff0c\u5b83\u59cb\u7ec8\u79f0\u4e3a\u201cnext\u201d\u3002\u4e3a\u4e86\u907f\u514d\u6df7\u6dc6\uff0c\u8bf7\u59cb\u7ec8\u4f7f\u7528\u6b64\u7ea6\u5b9a\u3002<\/p>\n<p>\u6700\u597d\u5c06\u4e2d\u95f4\u4ef6\u89c6\u4e3a http \u8bf7\u6c42\u5728\u5230\u8fbe\u5e94\u7528\u7a0b\u5e8f\u4e4b\u524d\u5fc5\u987b\u7ecf\u8fc7\u7684\u4e00\u7cfb\u5217\u201c\u5c42\u201d\u3002\u6bcf\u4e00\u5c42\u90fd\u53ef\u4ee5\u68c0\u67e5\u8bf7\u6c42\uff0c\u751a\u81f3\u5b8c\u5168\u62d2\u7edd\u5b83\u3002<\/p>\n<hr>\n<h2> \u52a0\u8f7d\u4e2d\u95f4\u4ef6 <\/h2>\n<p>\u8981\u52a0\u8f7d\u4e2d\u95f4\u4ef6\u51fd\u6570\uff0c\u60a8\u53ef\u4ee5\u8c03\u7528 litheapp \u7c7b\u7684 use() \u65b9\u6cd5\uff0c\u5e76\u6307\u5b9a\u6240\u9700\u7684\u4e2d\u95f4\u4ef6\u51fd\u6570\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u5728\u6267\u884c\u5230\u6839\u8def\u5f84\uff08\/\uff09\u7684\u8def\u7531\u4e4b\u524d\u52a0\u8f7d mylogger \u4e2d\u95f4\u4ef6\u51fd\u6570\uff1a<\/p>\n<pre>$app = new \\lithe\\app;\n\n$mylogger = function ($req, $res, $next) {\n    echo 'logged';\n    $next();\n};\n\n$app-&gt;use($mylogger);\n\n$app-&gt;get('\/', function ($req, $res, $next) {\n    $res-&gt;send('hello world!');\n});\n<\/pre>\n<p>\u6bcf\u5f53\u5e94\u7528\u7a0b\u5e8f\u6536\u5230\u8bf7\u6c42\u65f6\uff0c\u5b83\u90fd\u4f1a\u6253\u5370\u6d88\u606f\u201clogged\u201d\u3002<\/p>\n<p>\u4e2d\u95f4\u4ef6\u52a0\u8f7d\u987a\u5e8f\u5f88\u91cd\u8981\uff1a\u5148\u52a0\u8f7d\u7684\u4e2d\u95f4\u4ef6\u51fd\u6570\u4e5f\u4f1a\u5148\u6267\u884c\u3002<\/p>\n<p>mylogger \u4e2d\u95f4\u4ef6\u51fd\u6570\u53ea\u662f\u6253\u5370\u4e00\u6761\u6d88\u606f\uff0c\u7136\u540e\u901a\u8fc7\u8c03\u7528 $next() \u51fd\u6570\u5c06\u8bf7\u6c42\u4f20\u9012\u7ed9\u5806\u6808\u4e0a\u7684\u4e0b\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u51fd\u6570\u3002<\/p>\n<hr>\n<h2> \u4f7f\u7528\u4e2d\u95f4\u4ef6 <\/h2>\n<p>lithe \u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u7c7b\u578b\u7684\u4e2d\u95f4\u4ef6\uff1a<\/p>\n<ul>\n<li>\u5e94\u7528\u7ea7\u4e2d\u95f4\u4ef6<\/li>\n<li>\u8def\u7531\u5668\u7ea7\u4e2d\u95f4\u4ef6<\/li>\n<li>\u7b2c\u4e09\u65b9\u4e2d\u95f4\u4ef6<\/li>\n<\/ul>\n<h3> \u5e94\u7528\u5c42\u4e2d\u95f4\u4ef6 <\/h3>\n<p>\u4f7f\u7528 use() \u548c method() \u65b9\u6cd5\u5c06\u5e94\u7528\u7a0b\u5e8f\u7ea7\u4e2d\u95f4\u4ef6\u7ed1\u5b9a\u5230\u5e94\u7528\u7a0b\u5e8f\u5bf9\u8c61\u7684\u5b9e\u4f8b\uff0c\u5176\u4e2d method \u662f\u4e2d\u95f4\u4ef6\u51fd\u6570\u5904\u7406\u7684\u8bf7\u6c42\u7684 http \u65b9\u6cd5\uff08\u4f8b\u5982 get\u3001put \u6216 post\uff09\u5c0f\u5199\u3002<\/p>\n<p>\u6b64\u793a\u4f8b\u663e\u793a\u4e86\u4e00\u4e2a\u6ca1\u6709\u6c47\u7f16\u8def\u5f84\u7684\u4e2d\u95f4\u4ef6\u51fd\u6570\u3002\u6bcf\u6b21\u5e94\u7528\u7a0b\u5e8f\u6536\u5230\u8bf7\u6c42\u65f6\u90fd\u4f1a\u6267\u884c\u8be5\u51fd\u6570\u3002<\/p>\n<pre>$app-&gt;use(function ($req, $res, $next) {\n    echo 'hello world!';\n    $next();\n});\n<\/pre>\n<p>\u4e0b\u9762\u7684\u793a\u4f8b\u663e\u793a\u4e86\u4e00\u4e2a\u5904\u7406\u8def\u5f84 \/user\/:id \u4e2d\u7684 get \u8bf7\u6c42\u7684\u4e2d\u95f4\u4ef6\u3002<\/p>\n<pre>$app-&gt;get('\/user\/:id', function ($req, $res, $next) {\n    \/\/ se o id do usu\u00e1rio for '0', passa para o pr\u00f3ximo middleware\n    if ($req-&gt;param('id') === '0') {\n        return $next();\n    } \n\n    \/\/ caso contr\u00e1rio, envia uma resposta espec\u00edfica\n    $res-&gt;send('id n\u00e3o \u00e9 0');\n}, function ($req, $res) {\n    \/\/ envia uma resposta quando o id for '0'\n    $res-&gt;send('regular');\n});\n<\/pre>\n<h3> \u8def\u7531\u5668\u7ea7\u4e2d\u95f4\u4ef6 <\/h3>\n<p>\u8def\u7531\u5668\u7ea7\u4e2d\u95f4\u4ef6\u7684\u5de5\u4f5c\u65b9\u5f0f\u4e0e\u5e94\u7528\u7a0b\u5e8f\u7ea7\u4e2d\u95f4\u4ef6\u76f8\u540c\uff0c\u53ea\u662f\u5b83\u7ed1\u5b9a\u5230 lithehttprouter \u7684\u5b9e\u4f8b\u3002<\/p>\n<pre>$router = new \\lithe\\http\\router;\n<\/pre>\n<p>\u4f7f\u7528 use \u548c method \u51fd\u6570\u52a0\u8f7d\u8def\u7531\u5668\u7ea7\u4e2d\u95f4\u4ef6\u3002<\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u4ee3\u7801\u5c55\u793a\u4e86\u4f7f\u7528\u8def\u7531\u5668\u7ea7\u4e2d\u95f4\u4ef6\u7684\u4e2d\u95f4\u4ef6\u7cfb\u7edf\uff1a<\/p>\n<pre>$router = new \\lithe\\http\\router;\n\n\/\/ middleware de n\u00edvel de roteador para todas as rotas do roteador\n$router-&gt;use(function ($req, $res, $next) {\n    echo 'time: ', date('h:i:s'), '&lt;br&gt;';\n    $next();\n});\n\n$router-&gt;get('\/user\/:id', function ($req, $res, $next) {\n    \/\/ verifica se o id do usu\u00e1rio \u00e9 '0'; se for, redireciona para \/\n    if ($req-&gt;param('id') === '0') {\n        $res-&gt;redirect('\/');\n    }\n    \/\/ caso contr\u00e1rio, passa o controle para o pr\u00f3ximo middleware na pilha\n    $next()\n}, function ($req, $res, $next) {\n  echo $req-&gt;param('id');\n  $res-&gt;render('special');\n});\n\n\/\/ monta o roteador na aplica\u00e7\u00e3o\n$app-&gt;use('\/api', $router);\n<\/pre>\n<h3> \u7b2c\u4e09\u65b9\u4e2d\u95f4\u4ef6 <\/h3>\n<p>\u4f7f\u7528\u7b2c\u4e09\u65b9\u4e2d\u95f4\u4ef6\u4e3a lithe \u5e94\u7528\u7a0b\u5e8f\u6dfb\u52a0\u529f\u80fd\u3002<\/p>\n<p>\u5b89\u88c5\u6240\u9700\u529f\u80fd\u6240\u9700\u7684 php \u6a21\u5757\uff0c\u7136\u540e\u5728\u5e94\u7528\u7a0b\u5e8f\u7ea7\u522b\u6216\u8def\u7531\u5668\u7ea7\u522b\u5c06\u5176\u52a0\u8f7d\u5230\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u4e2d\u3002<\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u8bf4\u660e\u4e86\u52a0\u8f7d\u4f1a\u8bdd\u4e2d\u95f4\u4ef6\uff0c\u5373 lithemiddlewaresessionsession \u51fd\u6570\u3002<\/p>\n<pre>use function lithe\\middleware\\session\\session;\n\n$app = new \\lithe\\app;\n\n$app-&gt;use(session([\n    'secure' =&gt; true\n]));\n<\/pre>\n<p>lithe \u5e38\u7528\u7684\u7b2c\u4e09\u65b9\u4e2d\u95f4\u4ef6\u529f\u80fd\u7684\u90e8\u5206\u5217\u8868\uff0c\u8bf7\u53c2\u9605\uff1a\u7b2c\u4e09\u65b9\u4e2d\u95f4\u4ef6\u3002<\/p>\n<h2> \u53ef\u914d\u7f6e\u7684\u4e2d\u95f4\u4ef6 <\/h2>\n<p>\u5982\u679c\u60a8\u9700\u8981\u53ef\u914d\u7f6e\u7684\u4e2d\u95f4\u4ef6\uff0c\u8bf7\u521b\u5efa\u4e00\u4e2a\u63a5\u53d7\u9009\u9879\u6570\u7ec4\u6216\u5176\u4ed6\u53c2\u6570\u7684\u51fd\u6570\uff0c\u7136\u540e\u6839\u636e\u8f93\u5165\u53c2\u6570\u8fd4\u56de\u4e2d\u95f4\u4ef6\u5b9e\u73b0\u3002<\/p>\n<pre>&lt;?php\nfunction my_middleware ($options) {\n    return function ($req, $res, $next) use ($options) {\n        \/\/ implementa\u00e7\u00e3o do middleware com base na array de op\u00e7\u00f5es\n\n        \/\/ chama o pr\u00f3ximo middleware\n        $next();\n    };\n};\n<\/pre>\n<p>\u73b0\u5728\u53ef\u4ee5\u4f7f\u7528\u4e2d\u95f4\u4ef6\u4e86\uff0c\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<pre>$app-&gt;use(my_middleware(['option1' =&gt; '1', 'option2' =&gt; '2']));\n<\/pre>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n<p> \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb \u5220\u9664<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Middleware no Lithe: Como Funciona e Como Criar o Seu Pr\u00f3prio \u6536\u85cf \u5404\u4f4d\u5c0f\u4f19\u4f34\u4eec\uff0c\u5927\u5bb6\u597d\u5440\uff01\u770b\u770b\u4eca\u5929\u6211\u53c8\u7ed9\u5404\u4f4d\u5e26\u6765\u4e86\u4ec0\u4e48\u6587\u7ae0\uff1f\u672c\u6587\u6807\u9898\u662f\u300aMiddleware no Lithe: Como Funciona e Como Criar o Seu Pr\u00f3prio\u300b\uff0c\u5f88\u660e\u663e\u662f\u5173\u4e8e\u6587\u7ae0\u7684\u6587\u7ae0\u54c8\u54c8\u54c8\uff0c\u5176\u4e2d\u5185\u5bb9\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\uff0c\u5982\u679c\u80fd\u5e2e\u5230\u4f60\uff0c\u89c9\u5f97\u5f88\u4e0d\u9519\u7684\u8bdd\uff0c\u6b22\u8fce\u5404\u4f4d\u591a\u591a\u70b9\u8bc4\u548c\u5206\u4eab\uff01 \u4e2d\u95f4\u4ef6\u63d0\u4f9b\u4e86\u4e00\u79cd\u65b9\u4fbf\u7684\u673a\u5236\u6765\u68c0\u67e5\u548c\u8fc7\u6ee4\u8fdb\u5165\u5e94\u7528\u7a0b\u5e8f\u7684 http \u8bf7\u6c42\u3002\u4f8b\u5982\uff0clithe \u5305\u542b\u7528\u4e8e\u68c0\u67e5\u5e94\u7528\u7a0b\u5e8f\u7528\u6237\u662f\u5426\u7ecf\u8fc7\u8eab\u4efd\u9a8c\u8bc1\u7684\u4e2d\u95f4\u4ef6\u3002\u5982\u679c\u7528\u6237\u672a\u7ecf\u8fc7\u8eab\u4efd\u9a8c\u8bc1\uff0c\u4e2d\u95f4\u4ef6\u4f1a\u5c06\u7528\u6237\u91cd\u5b9a\u5411\u5230\u5e94\u7528\u7a0b\u5e8f\u7684\u767b\u5f55\u5c4f\u5e55\u3002\u4f46\u662f\uff0c\u5982\u679c\u7528\u6237\u7ecf\u8fc7\u8eab\u4efd\u9a8c\u8bc1\uff0c\u4e2d\u95f4\u4ef6\u5c06\u5141\u8bb8\u8bf7\u6c42\u5728\u5e94\u7528\u7a0b\u5e8f\u5185\u7ee7\u7eed\u8fdb\u884c\u3002 \u4e2d\u95f4\u4ef6\u5728 lithe \u4e2d\u7684\u5de5\u4f5c\u539f\u7406 \u5728 lithe \u4e2d\uff0c\u4e2d\u95f4\u4ef6\u662f\u53ef\u4ee5\u8bbf\u95ee\u5e94\u7528\u7a0b\u5e8f\u8bf7\u6c42\u54cd\u5e94\u5faa\u73af\u4e2d\u7684\u8bf7\u6c42\u5bf9\u8c61 ($req)\u3001\u54cd\u5e94\u5bf9\u8c61 ($res) \u548c $next \u51fd\u6570\u7684\u51fd\u6570\u3002 $next \u51fd\u6570\u662f lithe \u8def\u7531\u5668\u4e2d\u7684\u4e00\u4e2a\u51fd\u6570\uff0c\u8c03\u7528\u65f6\u4f1a\u6267\u884c\u5f53\u524d\u4e2d\u95f4\u4ef6\u65c1\u8fb9\u7684\u4e2d\u95f4\u4ef6\u3002 \u4e2d\u95f4\u4ef6\u51fd\u6570\u63d0\u4f9b\u4e86\u4e00\u79cd\u65b9\u4fbf\u7684\u673a\u5236\u6765\u68c0\u67e5\u3001\u8fc7\u6ee4\u548c\u5904\u7406\u8fdb\u5165\u5e94\u7528\u7a0b\u5e8f\u7684 http \u8bf7\u6c42\u3002 \u4e2d\u95f4\u4ef6\u51fd\u6570\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b\u4efb\u52a1\uff1a \u8fd0\u884c\u4efb\u4f55\u4ee3\u7801\u3002 \u66f4\u6539\u8bf7\u6c42\u548c\u54cd\u5e94\u5bf9\u8c61\u3002 \u7ed3\u675f\u8bf7\u6c42-\u54cd\u5e94\u5468\u671f\u3002 \u8c03\u7528\u5806\u6808\u4e2d\u7684\u4e0b\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u3002 \u5982\u679c\u5f53\u524d\u4e2d\u95f4\u4ef6\u51fd\u6570\u6ca1\u6709\u7ed3\u675f\u8bf7\u6c42-\u54cd\u5e94\u5468\u671f\uff0c\u5219\u5fc5\u987b\u8c03\u7528 $next() \u5c06\u63a7\u5236\u6743\u4f20\u9012\u7ed9\u4e0b\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u51fd\u6570\u3002\u5426\u5219\uff0c\u8bf7\u6c42\u5c06\u88ab\u7b49\u5f85\u5904\u7406\u3002 \u4e2d\u95f4\u4ef6\u529f\u80fd\u7684\u5143\u7d20 \u4ee5\u4e0b\u4ee3\u7801\u663e\u793a\u4e86\u4e2d\u95f4\u4ef6\u51fd\u6570\u8c03\u7528\u7684\u5143\u7d20\uff1a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-49152","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=49152"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49152\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}