{"id":5171,"date":"2016-07-12T14:15:33","date_gmt":"2016-07-12T06:15:33","guid":{"rendered":"https:\/\/sdeno.com\/?p=5171"},"modified":"2016-07-12T14:19:15","modified_gmt":"2016-07-12T06:19:15","slug":"express-4-x-%e4%b8%ad%e6%96%87%e6%89%8b%e5%86%8capi","status":"publish","type":"post","link":"https:\/\/sdeno.com\/?p=5171","title":{"rendered":"Express 4.x \u4e2d\u6587\u624b\u518cAPI"},"content":{"rendered":"<h2 style=\"color: #2c3e50;\" data-anchor-id=\"lh1o\">\u6765\u6e90\uff1a<a href=\"https:\/\/www.zybuluo.com\/XiangZhou\/note\/208532\" target=\"_blank\">https:\/\/www.zybuluo.com\/XiangZhou\/note\/208532<\/a><\/h2>\n<h2 id=\"express\" style=\"color: #2c3e50;\" data-anchor-id=\"lh1o\">express()<\/h2>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"0baf\"><code style=\"color: #2c3e50;\">express()<\/code>\u7528\u6765\u521b\u5efa\u4e00\u4e2aExpress\u7684\u7a0b\u5e8f\u3002<code style=\"color: #2c3e50;\">express()<\/code>\u65b9\u6cd5\u662f<strong style=\"font-weight: bold;\"><em style=\"font-style: italic;\">express<\/em><\/strong>\u6a21\u5757\u5bfc\u51fa\u7684\u9876\u5c42\u65b9\u6cd5\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> express <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> require<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'express'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> app <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> express<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h3 id=\"methods\" style=\"color: #2c3e50;\" data-anchor-id=\"hpe1\">Methods<\/h3>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"expressstaticroot-options\" style=\"color: #2c3e50;\" data-anchor-id=\"3ddq\">express.static(root, [options])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"dnvi\"><code style=\"color: #2c3e50;\">express.static<\/code>\u662fExpress\u4e2d\u552f\u4e00\u7684\u5185\u5efa\u4e2d\u95f4\u4ef6\u3002\u5b83\u4ee5<a style=\"color: #0088cc;\" href=\"https:\/\/github.com\/expressjs\/serve-static?_ga=1.1179825.1201680737.1446005628\" target=\"_blank\">server-static<\/a>\u6a21\u5757\u4e3a\u57fa\u7840\u5f00\u53d1\uff0c\u8d1f\u8d23\u6258\u7ba1 Express \u5e94\u7528\u5185\u7684\u9759\u6001\u8d44\u6e90\u3002<br \/>\n\u53c2\u6570<code style=\"color: #2c3e50;\">root<\/code>\u4e3a\u9759\u6001\u8d44\u6e90\u7684\u6240\u5728\u7684\u6839\u76ee\u5f55\u3002<br \/>\n\u53c2\u6570<code style=\"color: #2c3e50;\">options<\/code>\u662f\u53ef\u9009\u7684\uff0c\u652f\u6301\u4ee5\u4e0b\u7684\u5c5e\u6027\uff1a<\/p>\n<table class=\"table table-striped-white table-bordered\" style=\"color: #2c3e50;\" data-anchor-id=\"5xgv\">\n<thead>\n<tr>\n<th style=\"font-weight: bold;\">\u5c5e\u6027<\/th>\n<th style=\"font-weight: bold;\">\u63cf\u8ff0<\/th>\n<th style=\"font-weight: bold;\">\u7c7b\u578b<\/th>\n<th style=\"font-weight: bold;\">\u9ed8\u8ba4\u503c<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>dotfiles<\/td>\n<td>\u662f\u5426\u54cd\u5e94\u70b9\u6587\u4ef6\u3002\u4f9b\u9009\u62e9\u7684\u503c\u6709&#8221;allow&#8221;\uff0c&#8221;deny&#8221;\u548c&#8221;ignore&#8221;<\/td>\n<td>String<\/td>\n<td>&#8220;ignore&#8221;<\/td>\n<\/tr>\n<tr>\n<td>etag<\/td>\n<td>\u4f7f\u80fd\u6216\u8005\u5173\u95edetag<\/td>\n<td>Boolean<\/td>\n<td>true<\/td>\n<\/tr>\n<tr>\n<td>extensions<\/td>\n<td>\u8bbe\u7f6e\u6587\u4ef6\u5ef6\u671f\u56de\u9000<\/td>\n<td>Boolean<\/td>\n<td>true<\/td>\n<\/tr>\n<tr>\n<td>index<\/td>\n<td>\u53d1\u9001\u76ee\u5f55\u7d22\u5f15\u6587\u4ef6\u3002\u8bbe\u7f6efalse\u5c06\u4e0d\u53d1\u9001\u3002<\/td>\n<td>Mixed<\/td>\n<td>&#8220;index.html&#8221;<\/td>\n<\/tr>\n<tr>\n<td>lastModified<\/td>\n<td>\u8bbe\u7f6e\u6587\u4ef6\u5728\u7cfb\u7edf\u4e2d\u7684\u6700\u540e\u4fee\u6539\u65f6\u95f4\u5230<code style=\"color: #2c3e50;\">Last-Modified<\/code>\u5934\u90e8\u3002\u53ef\u80fd\u7684\u53d6\u503c\u6709<code style=\"color: #2c3e50;\">false<\/code>\u548c<code style=\"color: #2c3e50;\">true<\/code>\u3002<\/td>\n<td>Boolean<\/td>\n<td>true<\/td>\n<\/tr>\n<tr>\n<td>maxAge<\/td>\n<td>\u5728Cache-Control\u5934\u90e8\u4e2d\u8bbe\u7f6e<code style=\"color: #2c3e50;\">max-age<\/code>\u5c5e\u6027\uff0c\u7cbe\u5ea6\u4e3a\u6beb\u79d2(ms)\u6216\u5219\u4e00\u6bb5<a style=\"color: #0088cc;\" href=\"https:\/\/www.npmjs.org\/package\/ms\" target=\"_blank\">ms format<\/a>\u7684\u5b57\u7b26\u4e32<\/td>\n<td>Number<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>redirect<\/td>\n<td>\u5f53\u8bf7\u6c42\u7684pathname\u662f\u4e00\u4e2a\u76ee\u5f55\u7684\u65f6\u5019\uff0c\u91cd\u5b9a\u5411\u5230\u5c3e\u968f&#8221;\/&#8221;<\/td>\n<td>Boolean<\/td>\n<td>true<\/td>\n<\/tr>\n<tr>\n<td>setHeaders<\/td>\n<td>\u5f53\u54cd\u5e94\u9759\u6001\u6587\u4ef6\u8bf7\u6c42\u65f6\u8bbe\u7f6eheaders\u7684\u65b9\u6cd5<\/td>\n<td>Funtion<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"p200\">\u5982\u679c\u4f60\u60f3\u83b7\u5f97\u66f4\u591a\u5173\u4e8e\u4f7f\u7528\u4e2d\u95f4\u4ef6\u7684\u7ec6\u8282\uff0c\u4f60\u53ef\u4ee5\u67e5\u9605<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/starter\/static-files.html\" target=\"_blank\">Serving static files in Express<\/a>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h2 id=\"application\" style=\"color: #2c3e50;\" data-anchor-id=\"r2u0\">Application()<\/h2>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"kt2p\"><code style=\"color: #2c3e50;\">app<\/code>\u5bf9\u8c61\u4e00\u822c\u7528\u6765\u8868\u793aExpress\u7a0b\u5e8f\u3002\u901a\u8fc7\u8c03\u7528Express\u6a21\u5757\u5bfc\u51fa\u7684\u9876\u5c42\u7684<code style=\"color: #2c3e50;\">express()<\/code>\u65b9\u6cd5\u6765\u521b\u5efa\u5b83:<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> express <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> require<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'express'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> app <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> express<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'hello world!'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">listen<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">3000<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"w3sy\"><code style=\"color: #2c3e50;\">app<\/code>\u5bf9\u8c61\u5177\u6709\u4ee5\u4e0b\u7684\u65b9\u6cd5\uff1a<\/p>\n<ul style=\"color: #2c3e50;\" data-anchor-id=\"ly8h\">\n<li>\u8def\u7531HTTP\u8bf7\u6c42\uff1b\u5177\u4f53\u53ef\u4ee5\u770b<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#app.METHOD\" target=\"_blank\">app.METHOD<\/a>\u548c<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#app.param\" target=\"_blank\">app.param<\/a>\u8fd9\u4e24\u4e2a\u4f8b\u5b50\u3002<\/li>\n<li>\u914d\u7f6e\u4e2d\u95f4\u4ef6\uff1b\u5177\u4f53\u8bf7\u770b<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#app.route\" target=\"_blank\">app.route<\/a>\u3002<\/li>\n<li>\u6e32\u67d3HTML\u89c6\u56fe\uff1b\u5177\u4f53\u8bf7\u770b<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#app.render\" target=\"_blank\">app.render<\/a>\u3002<\/li>\n<li>\u6ce8\u518c\u6a21\u677f\u5f15\u64ce\uff1b\u5177\u4f53\u8bf7\u770b<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#app.engine\" target=\"_blank\">app.engine<\/a>\u3002<\/li>\n<\/ul>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"5863\">\u5b83\u8fd8\u6709\u4e00\u4e9b\u5c5e\u6027\u8bbe\u7f6e\uff0c\u8fd9\u4e9b\u5c5e\u6027\u53ef\u4ee5\u6539\u53d8\u7a0b\u5e8f\u7684\u884c\u4e3a\u3002\u83b7\u5f97\u66f4\u591a\u7684\u4fe1\u606f\uff0c\u53ef\u4ee5\u67e5\u9605<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#app.settings.table\" target=\"_blank\">Application settings<\/a>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h3 id=\"properties\" style=\"color: #2c3e50;\" data-anchor-id=\"emuw\">Properties<\/h3>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"applocals\" style=\"color: #2c3e50;\" data-anchor-id=\"kxr7\">app.locals<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"61dv\"><code style=\"color: #2c3e50;\">app.locals<\/code>\u5bf9\u8c61\u662f\u4e00\u4e2ajavascript\u5bf9\u8c61\uff0c\u5b83\u7684\u5c5e\u6027\u5c31\u662f\u7a0b\u5e8f\u672c\u5730\u7684\u53d8\u91cf\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">locals<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">title<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; 'My App'<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">locals<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">email<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; 'me@myapp.com'<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"q4eh\">\u4e00\u65e6\u8bbe\u5b9a\uff0c<code style=\"color: #2c3e50;\">app.locals<\/code>\u7684\u5404\u5c5e\u6027\u503c\u5c06\u8d2f\u7a7f\u7a0b\u5e8f\u7684\u6574\u4e2a\u751f\u547d\u5468\u671f\uff0c\u4e0e\u5176\u76f8\u53cd\u7684\u662f<code style=\"color: #2c3e50;\">res.locals<\/code>\uff0c\u5b83\u53ea\u5728\u8fd9\u6b21\u8bf7\u6c42\u7684\u751f\u547d\u5468\u671f\u4e2d\u6709\u6548\u3002<\/p>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"7jbu\">\u5728\u7a0b\u5e8f\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5728\u6e32\u67d3\u6a21\u677f\u65f6\u4f7f\u7528\u8fd9\u4e9b\u672c\u5730\u53d8\u91cf\u3002\u5b83\u4eec\u662f\u975e\u5e38\u6709\u7528\u7684\uff0c\u53ef\u4ee5\u4e3a\u6a21\u677f\u63d0\u4f9b\u4e00\u4e9b\u6709\u7528\u7684\u65b9\u6cd5\uff0c\u4ee5\u53ca<code style=\"color: #2c3e50;\">app<\/code>\u7ea7\u522b\u7684\u6570\u636e\u3002\u901a\u8fc7<code style=\"color: #2c3e50;\">req.app.locals<\/code>(\u5177\u4f53\u67e5\u770b<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#req.app\" target=\"_blank\">req.app<\/a>)\uff0cLocals\u53ef\u4ee5\u5728\u4e2d\u95f4\u4ef6\u4e2d\u4f7f\u7528\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">locals<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">title <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"str\" style=\"color: #008800;\">'My App'<\/span><span class=\"pun\" style=\"color: #666600;\">;<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">locals<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">strftime <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> require<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'strftime'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">locals<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">email <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"str\" style=\"color: #008800;\">'me@myapp.com'<\/span><span class=\"pun\" style=\"color: #666600;\">;<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"appmountpath\" style=\"color: #2c3e50;\" data-anchor-id=\"vuee\">app.mountpath<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"2lnw\"><code style=\"color: #2c3e50;\">app.mountpath<\/code>\u5c5e\u6027\u662f\u5b50\u7a0b\u5e8f\u6302\u8f7d\u7684\u8def\u5f84\u6a21\u5f0f\u3002<\/p>\n<blockquote class=\"white-blockquote\" style=\"color: #2c3e50;\" data-anchor-id=\"4tjs\">\n<p style=\"font-weight: 300;\">\u4e00\u4e2a\u5b50\u7a0b\u5e8f\u662f\u4e00\u4e2a<code style=\"color: #2c3e50;\">express<\/code>\u7684\u5b9e\u4f8b\uff0c\u5176\u53ef\u4ee5\u88ab\u7528\u6765\u4f5c\u4e3a\u8def\u7531\u53e5\u67c4\u6765\u5904\u7406\u8bf7\u6c42\u3002<\/p>\n<\/blockquote>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> express <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> require<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'express'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> app <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> express<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ the main app<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> admin <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> express<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ the sub app<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">admin<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">admin<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">mountpath<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ \/admin<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Admin Homepage'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/admin'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> admin<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ mount the sub app<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"u5kx\">\u5b83\u548creq\u5bf9\u8c61\u7684<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#req.baseUrl\" target=\"_blank\">baseUrl<\/a>\u5c5e\u6027\u6bd4\u8f83\u76f8\u4f3c\uff0c\u9664\u4e86<code style=\"color: #2c3e50;\">req.baseUrl<\/code>\u662f\u5339\u914d\u7684URL\u8def\u5f84\uff0c\u800c\u4e0d\u662f\u5339\u914d\u7684\u6a21\u5f0f\u3002\u5982\u679c\u4e00\u4e2a\u5b50\u7a0b\u5e8f\u88ab\u6302\u8f7d\u5728\u591a\u6761\u8def\u5f84\u6a21\u5f0f\uff0c<code style=\"color: #2c3e50;\">app.mountpath<\/code>\u5c31\u662f\u4e00\u4e2a\u5173\u4e8e\u6302\u8f7d\u8def\u5f84\u6a21\u5f0f\u9879\u7684\u5217\u8868\uff0c\u5982\u4e0b\u9762\u4f8b\u5b50\u6240\u793a\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> admin <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> express<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">admin<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">admin<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">mountpath<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ ['adm*n', '\/manager'] <\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Admin Homepage'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> secret <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> express<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">secret<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">secret<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">mountpath<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ \/secr*t<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Admin secret'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">admin<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/secr*t'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> secret<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ load the 'secret' router on '\/secr*t', on the 'admin' sub app<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">([<\/span><span class=\"str\" style=\"color: #008800;\">'\/adm*n'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'\/manager'<\/span><span class=\"pun\" style=\"color: #666600;\">],<\/span><span class=\"pln\" style=\"color: #000000;\"> admin<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ load the 'admin' router on '\/adm*n' and '\/manager' , on the parent app<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h3 id=\"events\" style=\"color: #2c3e50;\" data-anchor-id=\"4f8k\">Events<\/h3>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"apponmount-callbackparent\" style=\"color: #2c3e50;\" data-anchor-id=\"ctky\">app.on(&#8216;mount&#8217;, callback(parent))<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"nxel\">\u5f53\u5b50\u7a0b\u5e8f\u88ab\u6302\u8f7d\u5230\u7236\u7a0b\u5e8f\u65f6\uff0c<code style=\"color: #2c3e50;\">mount<\/code>\u4e8b\u4ef6\u88ab\u53d1\u5c04\u3002\u7236\u7a0b\u5e8f\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570\uff0c\u4f20\u9012\u7ed9\u56de\u8c03\u65b9\u6cd5\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> admin <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> express<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">admin<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">on<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'mount'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">parent<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Admin Mounted'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">parent<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ refers to the parent app<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">admin<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Admin Homepage'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/admin'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> admin<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h3 id=\"methods-1\" style=\"color: #2c3e50;\" data-anchor-id=\"2a8v\">Methods<\/h3>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"appallpath-callback-callback\" style=\"color: #2c3e50;\" data-anchor-id=\"wnz2\">app.all(path, callback[, callback &#8230;]<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"pehk\"><code style=\"color: #2c3e50;\">app.all<\/code>\u65b9\u6cd5\u548c\u6807\u51c6\u7684<code style=\"color: #2c3e50;\">app.METHOD()<\/code>\u65b9\u6cd5\u76f8\u4f3c\uff0c\u9664\u4e86\u5b83\u5339\u914d\u6240\u6709\u7684HTTP\u52a8\u8bcd\u3002<br \/>\n\u5bf9\u4e8e\u7ed9\u4e00\u4e2a\u7279\u6b8a\u524d\u7f00\u6620\u5c04\u4e00\u4e2a\u5168\u5c40\u7684\u903b\u8f91\u5904\u7406\uff0c\u6216\u8005\u65e0\u6761\u4ef6\u5339\u914d\uff0c\u5b83\u662f\u5f88\u6709\u6548\u7684\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u628a\u4e0b\u9762\u5185\u5bb9\u653e\u5728\u6240\u6709\u5176\u4ed6\u7684\u8def\u7531\u5b9a\u4e49\u7684\u524d\u9762\uff0c\u5b83\u8981\u6c42\u6240\u6709\u4ece\u8fd9\u4e2a\u70b9\u5f00\u59cb\u7684\u8def\u7531\u9700\u8981\u8ba4\u8bc1\u548c\u81ea\u52a8\u52a0\u8f7d\u4e00\u4e2a\u7528\u6237\u3002\u8bb0\u4f4f\u8fd9\u4e9b\u56de\u8c03\u5e76\u4e0d\u662f\u4e00\u5b9a\u662f\u7ec8\u70b9:<code style=\"color: #2c3e50;\">loadUser<\/code>\u53ef\u4ee5\u5728\u5b8c\u6210\u4e86\u4e00\u4e2a\u4efb\u52a1\u540e\uff0c\u8c03\u7528<code style=\"color: #2c3e50;\">next()<\/code>\u65b9\u6cd5\u6765\u7ee7\u7eed\u5339\u914d\u968f\u540e\u7684\u8def\u7531\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">all<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'*'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> requireAuthentication<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> loadUser<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"g36g\">\u6216\u8005\u8fd9\u79cd\u76f8\u7b49\u7684\u5f62\u5f0f:<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">all<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'*'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> requireAuthentication<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">all<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'*'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> loadUser<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"e4d7\">\u53e6\u4e00\u4e2a\u4f8b\u5b50\u662f\u5168\u5c40\u7684\u767d\u540d\u5355\u65b9\u6cd5\u3002\u8fd9\u4e2a\u4f8b\u5b50\u548c\u524d\u9762\u7684\u5f88\u50cf\uff0c\u7136\u800c\u5b83\u53ea\u662f\u9650\u5236\u4ee5<code style=\"color: #2c3e50;\">\/api<\/code>\u5f00\u5934\u7684\u8def\u5f84\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">all<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/api\/*'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> requireAuthentication<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"appdeletepath-callback-callback\" style=\"color: #2c3e50;\" data-anchor-id=\"yr9u\">app.delete(path, callback[, callback &#8230;])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"8z7j\">\u8def\u7531<code style=\"color: #2c3e50;\">HTTP DELETE<\/code>\u8bf7\u6c42\u5230\u6709\u7279\u6b8a\u56de\u8c03\u65b9\u6cd5\u7684\u7279\u6b8a\u7684\u8def\u5f84\u3002\u83b7\u53d6\u66f4\u591a\u7684\u4fe1\u606f\uff0c\u53ef\u4ee5\u67e5\u9605<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/guide\/routing.html\" target=\"_blank\">routing guide<\/a>\u3002<br \/>\n\u4f60\u53ef\u4ee5\u63d0\u4f9b\u591a\u4e2a\u56de\u8c03\u51fd\u6570\uff0c\u5b83\u4eec\u7684\u884c\u4e3a\u548c\u4e2d\u95f4\u4ef6\u4e00\u6837\uff0c\u9664\u4e86\u8fd9\u4e9b\u56de\u8c03\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528<code style=\"color: #2c3e50;\">next('router')<\/code>\u6765\u7ed5\u8fc7\u5269\u4f59\u7684\u8def\u7531\u56de\u8c03\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u673a\u5236\u6765\u4e3a\u4e00\u4e2a\u8def\u7531\u8bbe\u7f6e\u4e00\u4e9b\u524d\u63d0\u6761\u4ef6\uff0c\u5982\u679c\u4e0d\u80fd\u6ee1\u8db3\u5f53\u524d\u8def\u7531\u7684\u5904\u7406\u6761\u4ef6\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u4f20\u9012\u63a7\u5236\u5230\u968f\u540e\u7684\u8def\u7531\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">delete<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'DELETE request to homepage'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"appdisablename\" style=\"color: #2c3e50;\" data-anchor-id=\"t8u9\">app.disable(name)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"603z\">\u8bbe\u7f6e\u7c7b\u578b\u4e3a\u5e03\u5c14\u7684\u8bbe\u7f6e\u540d\u4e3a<code style=\"color: #2c3e50;\">name<\/code>\u7684\u503c\u4e3a<code style=\"color: #2c3e50;\">false<\/code>\uff0c\u6b64\u5904\u7684<code style=\"color: #2c3e50;\">name<\/code>\u662f<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#app.settings.table\" target=\"_blank\">app settings table<\/a>\u4e2d\u5404\u5c5e\u6027\u7684\u4e00\u4e2a\u3002\u8c03\u7528<code style=\"color: #2c3e50;\">app.set('foo', false)<\/code>\u548c\u8c03\u7528<code style=\"color: #2c3e50;\">app.disable('foo')<\/code>\u662f\u7b49\u4ef7\u7684\u3002<br \/>\n\u6bd4\u5982:<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">disable<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'trust proxy'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'trust proxy'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; false<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"appdisabledname\" style=\"color: #2c3e50;\" data-anchor-id=\"226n\">app.disabled(name)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"5f6b\">\u8fd4\u56de<code style=\"color: #2c3e50;\">true<\/code>\u5982\u679c\u5e03\u5c14\u7c7b\u578b\u7684\u8bbe\u7f6e\u503c<code style=\"color: #2c3e50;\">name<\/code>\u88ab\u7981\u7528\u4e3a<code style=\"color: #2c3e50;\">false<\/code>\uff0c\u6b64\u5904\u7684<code style=\"color: #2c3e50;\">name<\/code>\u662f<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#app.settings.table\" target=\"_blank\">app settings table<\/a>\u4e2d\u5404\u5c5e\u6027\u7684\u4e00\u4e2a\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">disabled<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'trust proxy'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; true<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">enable<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'trust proxy'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">disabled<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'trust proxy'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; false<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"appenablename\" style=\"color: #2c3e50;\" data-anchor-id=\"hikr\">app.enable(name)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"b9ct\">\u8bbe\u7f6e\u5e03\u5c14\u7c7b\u578b\u7684\u8bbe\u7f6e\u503c<code style=\"color: #2c3e50;\">name<\/code>\u4e3a<code style=\"color: #2c3e50;\">true<\/code>\uff0c\u6b64\u5904\u7684<code style=\"color: #2c3e50;\">name<\/code>\u662f<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#app.settings.table\" target=\"_blank\">app settings table<\/a>\u4e2d\u5404\u5c5e\u6027\u7684\u4e00\u4e2a\u3002\u8c03\u7528<code style=\"color: #2c3e50;\">app.set('foo', true)<\/code>\u548c\u8c03\u7528<code style=\"color: #2c3e50;\">app.enable('foo')<\/code>\u662f\u7b49\u4ef7\u7684\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">enable<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'trust proxy'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'trust proxy'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; true<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"appenabledname\" style=\"color: #2c3e50;\" data-anchor-id=\"vt8k\">app.enabled(name)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"4efv\">\u8fd4\u56de<code style=\"color: #2c3e50;\">true<\/code>\u5982\u679c\u5e03\u5c14\u7c7b\u578b\u7684\u8bbe\u7f6e\u503c<code style=\"color: #2c3e50;\">name<\/code>\u88ab\u542f\u52a8\u4e3a<code style=\"color: #2c3e50;\">true<\/code>\uff0c\u6b64\u5904\u7684<code style=\"color: #2c3e50;\">name<\/code>\u662f<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#app.settings.table\" target=\"_blank\">app settings table<\/a>\u4e2d\u5404\u5c5e\u6027\u7684\u4e00\u4e2a\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">enabled<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'trust proxy'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; false<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">enable<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'trust proxy'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">enabled<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'trust proxy'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; true<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"appengineext-callback\" style=\"color: #2c3e50;\" data-anchor-id=\"54et\">app.engine(ext, callback)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"ax8x\">\u6ce8\u518c\u7ed9\u5b9a\u5f15\u64ce\u7684\u56de\u8c03\uff0c\u7528\u6765\u6e32\u67d3\u5904\u7406ext\u6587\u4ef6\u3002<br \/>\n\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cExpress\u9700\u8981\u4f7f\u7528<code style=\"color: #2c3e50;\">require()<\/code>\u6765\u52a0\u8f7d\u57fa\u4e8e\u6587\u4ef6\u6269\u5c55\u7684\u5f15\u64ce\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u5c1d\u8bd5\u6e32\u67d3\u4e00\u4e2a<code style=\"color: #2c3e50;\">foo.jade<\/code>\u6587\u4ef6\uff0cExpress\u5728\u5185\u90e8\u8c03\u7528\u4e0b\u9762\u7684\u5185\u5bb9\uff0c\u540c\u65f6\u7f13\u5b58<code style=\"color: #2c3e50;\">require()<\/code>\u7ed3\u679c\u4f9b\u968f\u540e\u7684\u8c03\u7528\uff0c\u6765\u52a0\u901f\u6027\u80fd\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">engine<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'jade'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> require<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'jade'<\/span><span class=\"pun\" style=\"color: #666600;\">).<\/span><span class=\"pln\" style=\"color: #000000;\">__express<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"zvyh\">\u4f7f\u7528\u4e0b\u9762\u7684\u65b9\u6cd5\u5bf9\u4e8e\u90a3\u4e9b\u6ca1\u6709\u63d0\u4f9b\u5f00\u7bb1\u5373\u7528\u7684<code style=\"color: #2c3e50;\">.__express<\/code>\u65b9\u6cd5\u7684\u6a21\u677f\uff0c\u6216\u8005\u4f60\u5e0c\u671b\u4f7f\u7528\u4e0d\u540c\u7684\u6a21\u677f\u5f15\u64ce\u6269\u5c55\u3002<br \/>\n\u6bd4\u5982\uff0c\u4f7f\u7528EJS\u6a21\u677f\u5f15\u64ce\u6765\u6e32\u67d3<code style=\"color: #2c3e50;\">.html<\/code>\u6587\u4ef6\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">engine<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'html'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> require<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'ejs'<\/span><span class=\"pun\" style=\"color: #666600;\">).<\/span><span class=\"pln\" style=\"color: #000000;\">renderFile<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"qh5h\">\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0cEJS\u63d0\u4f9b\u4e86\u4e00\u4e2a<code style=\"color: #2c3e50;\">.renderFile<\/code>\u65b9\u6cd5\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u6ee1\u8db3\u4e86Express\u89c4\u5b9a\u7684\u7b7e\u540d\u89c4\u5219\uff1a<code style=\"color: #2c3e50;\">(path, options, callback)<\/code>\uff0c\u7136\u800c\u8bb0\u4f4f\u5728\u5185\u90e8\u5b83\u53ea\u662f<code style=\"color: #2c3e50;\">ejs.__express<\/code>\u7684\u4e00\u4e2a\u522b\u540d\uff0c\u6240\u4ee5\u4f60\u53ef\u4ee5\u5728\u4e0d\u505a\u4efb\u4f55\u4e8b\u7684\u60c5\u51b5\u4e0b\u76f4\u63a5\u4f7f\u7528<code style=\"color: #2c3e50;\">.ejs<\/code>\u6269\u5c55\u3002<br \/>\n\u4e00\u4e9b\u6a21\u677f\u5f15\u64ce\u6ca1\u6709\u9075\u5faa\u8fd9\u79cd\u89c4\u8303\uff0c<a style=\"color: #0088cc;\" href=\"https:\/\/github.com\/tj\/consolidate.js?_ga=1.260760333.1201680737.1446005628\" target=\"_blank\">consolidate.js<\/a>\u5e93\u6620\u5c04\u6a21\u677f\u5f15\u64ce\u4ee5\u4e0b\u9762\u7684\u4f7f\u7528\u65b9\u5f0f\uff0c\u6240\u4ee5\u4ed6\u4eec\u53ef\u4ee5\u65e0\u7f1d\u7684\u548cExpress\u5de5\u4f5c\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> engines <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> require<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'consolidate'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">engine<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'haml'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> engines<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">haml<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">engine<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'html'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> engines<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">hogan<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"appgetname\" style=\"color: #2c3e50;\" data-anchor-id=\"bc18\">app.get(name)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"10hc\">\u83b7\u5f97\u8bbe\u7f6e\u540d\u4e3a<code style=\"color: #2c3e50;\">name<\/code>\u7684app\u8bbe\u7f6e\u7684\u503c\uff0c\u6b64\u5904\u7684<code style=\"color: #2c3e50;\">name<\/code>\u662f<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#app.settings.table\" target=\"_blank\">app settings table<\/a>\u4e2d\u5404\u5c5e\u6027\u7684\u4e00\u4e2a\u3002<br \/>\n\u5982\u4e0b\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'title'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; undefined<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">set<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'title'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'My Site'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'title'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; 'My Site'<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"appgetpath-callback-callback\" style=\"color: #2c3e50;\" data-anchor-id=\"qwmb\">app.get(path, callback [, callback &#8230;])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"0bz7\">\u8def\u7531<code style=\"color: #2c3e50;\">HTTP GET<\/code>\u8bf7\u6c42\u5230\u6709\u7279\u6b8a\u56de\u8c03\u7684\u7279\u6b8a\u8def\u5f84\u3002\u83b7\u53d6\u66f4\u591a\u7684\u4fe1\u606f\uff0c\u53ef\u4ee5\u67e5\u9605<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/guide\/routing.html\" target=\"_blank\">routing guide<\/a>\u3002<br \/>\n\u4f60\u53ef\u4ee5\u63d0\u4f9b\u591a\u4e2a\u56de\u8c03\u51fd\u6570\uff0c\u5b83\u4eec\u7684\u884c\u4e3a\u548c\u4e2d\u95f4\u4ef6\u4e00\u6837\uff0c\u9664\u4e86\u8fd9\u4e9b\u56de\u8c03\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528<code style=\"color: #2c3e50;\">next('router')<\/code>\u6765\u7ed5\u8fc7\u5269\u4f59\u7684\u8def\u7531\u56de\u8c03\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u673a\u5236\u6765\u4e3a\u4e00\u4e2a\u8def\u7531\u8bbe\u7f6e\u4e00\u4e9b\u524d\u63d0\u6761\u4ef6\uff0c\u5982\u679c\u8bf7\u6c42\u6ca1\u80fd\u6ee1\u8db3\u5f53\u524d\u8def\u7531\u7684\u5904\u7406\u6761\u4ef6\uff0c\u90a3\u4e48\u4f20\u9012\u63a7\u5236\u5230\u968f\u540e\u7684\u8def\u7531\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'GET request to homepage'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"applistenport-hostname-backlog-callback\" style=\"color: #2c3e50;\" data-anchor-id=\"4jgz\">app.listen(port, [hostname], [backlog], [callback])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"ckic\">\u7ed1\u5b9a\u7a0b\u5e8f\u76d1\u542c\u7aef\u53e3\u5230\u6307\u5b9a\u7684\u4e3b\u673a\u548c\u7aef\u53e3\u53f7\u3002\u8fd9\u4e2a\u65b9\u6cd5\u548c<code style=\"color: #2c3e50;\">Node<\/code>\u4e2d\u7684<a style=\"color: #0088cc;\" href=\"http:\/\/nodejs.org\/api\/http.html#http_server_listen_port_hostname_backlog_callback\" target=\"_blank\">http.Server.listen()<\/a>\u662f\u4e00\u6837\u7684\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> express <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> require<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'express'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> app <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> express<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">listen<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">3000<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"9g9q\">\u901a\u8fc7\u8c03\u7528<code style=\"color: #2c3e50;\">express()<\/code>\u8fd4\u56de\u5f97\u5230\u7684<code style=\"color: #2c3e50;\">app<\/code>\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2aJavaScript\u7684<code style=\"color: #2c3e50;\">Function<\/code>\uff0c\u88ab\u8bbe\u8ba1\u7528\u6765\u4f5c\u4e3a\u4e00\u4e2a\u56de\u8c03\u4f20\u9012\u7ed9<code style=\"color: #2c3e50;\">Node HTTP servers<\/code>\u6765\u5904\u7406\u8bf7\u6c42\u3002\u8fd9\u6837\uff0c\u5176\u5c31\u53ef\u4ee5\u5f88\u7b80\u4fbf\u7684\u57fa\u4e8e\u540c\u4e00\u4efd\u4ee3\u7801\u63d0\u4f9bhttp\u548chttps\u7248\u672c\uff0c\u6240\u4ee5app\u6ca1\u6709\u4ece\u8fd9\u4e9b\u7ee7\u627f(\u5b83\u53ea\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u56de\u8c03)\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> express <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> require<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'express'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> https <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> require<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'https'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> http <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> require<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'http'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> http<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">createServer<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">).<\/span><span class=\"pln\" style=\"color: #000000;\">listen<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">80<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> https<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">createServer<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">options<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">).<\/span><span class=\"pln\" style=\"color: #000000;\">listen<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">443<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"6zs6\"><code style=\"color: #2c3e50;\">app.listen()<\/code>\u65b9\u6cd5\u662f\u4e0b\u9762\u6240\u793a\u7684\u4e00\u4e2a\u4fbf\u5229\u7684\u65b9\u6cd5(\u53ea\u9488\u5bf9HTTP\u534f\u8bae):<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">listen <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">()<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> server <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> http<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">createServer<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">this<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">return<\/span><span class=\"pln\" style=\"color: #000000;\"> server<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">listen<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">apply<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">server<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> arguments<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">};<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"appmethodpath-callback-callback\" style=\"color: #2c3e50;\" data-anchor-id=\"9imn\">app.METHOD(path, callback [, callback &#8230;])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"t7ni\">\u8def\u7531\u4e00\u4e2aHTTP\u8bf7\u6c42\uff0c<code style=\"color: #2c3e50;\">METHOD<\/code>\u662f\u8fd9\u4e2a\u8bf7\u6c42\u7684HTTP\u65b9\u6cd5\uff0c\u6bd4\u5982<code style=\"color: #2c3e50;\">GET<\/code>\uff0c<code style=\"color: #2c3e50;\">PUT<\/code>\uff0c<code style=\"color: #2c3e50;\">POST<\/code>\u7b49\u7b49\uff0c\u6ce8\u610f\u662f\u5c0f\u5199\u7684\u3002\u6240\u4ee5\uff0c\u5b9e\u9645\u7684\u65b9\u6cd5\u662f<code style=\"color: #2c3e50;\">app.get()<\/code>\uff0c<code style=\"color: #2c3e50;\">app.post()<\/code>\uff0c<code style=\"color: #2c3e50;\">app.put()<\/code>\u7b49\u7b49\u3002\u4e0b\u9762\u6709\u5173\u4e8e\u65b9\u6cd5\u7684\u5b8c\u6574\u7684\u8868\u3002<br \/>\n\u83b7\u53d6\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u770b<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/guide\/routing.html\" target=\"_blank\">routing guide<\/a>\u3002<br \/>\nExpress\u652f\u6301\u4e0b\u9762\u7684\u8def\u7531\u65b9\u6cd5\uff0c\u5bf9\u5e94\u4e0e\u540c\u540d\u7684HTTP\u65b9\u6cd5\uff1a<\/p>\n<table class=\"table table-striped-white table-bordered\" style=\"color: #2c3e50;\" data-anchor-id=\"mrp2\">\n<tbody>\n<tr>\n<td>\n<ul>\n<li>checkout<\/li>\n<li>connect<\/li>\n<li>copy<\/li>\n<li>delete<\/li>\n<li>get<\/li>\n<li>head<\/li>\n<li>lock<\/li>\n<li>merge<\/li>\n<li>mkactivity<\/li>\n<\/ul>\n<\/td>\n<td>\n<ul>\n<li>mkcol<\/li>\n<li>move<\/li>\n<li>m-search<\/li>\n<li>notify<\/li>\n<li>options<\/li>\n<li>patch<\/li>\n<li>post<\/li>\n<li>propfind<\/li>\n<li>proppatch<\/li>\n<\/ul>\n<\/td>\n<td>\n<ul>\n<li>purege<\/li>\n<li>put<\/li>\n<li>report<\/li>\n<li>search<\/li>\n<li>subscribe<\/li>\n<li>trace<\/li>\n<li>unlock<\/li>\n<li>unsubscribe<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<blockquote class=\"white-blockquote\" style=\"color: #2c3e50;\" data-anchor-id=\"tzqc\">\n<p style=\"font-weight: 300;\">\u5982\u679c\u4f7f\u7528\u4e0a\u8ff0\u65b9\u6cd5\u65f6\uff0c\u5bfc\u81f4\u4e86\u65e0\u6548\u7684javascript\u7684\u53d8\u91cf\u540d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e2d\u62ec\u53f7\u7b26\u53f7\uff0c\u6bd4\u5982,<code style=\"color: #2c3e50;\">app['m-search']('\/', function ...<\/code><\/p>\n<\/blockquote>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"6w5l\">\u4f60\u53ef\u4ee5\u63d0\u4f9b\u591a\u4e2a\u56de\u8c03\u51fd\u6570\uff0c\u5b83\u4eec\u7684\u884c\u4e3a\u548c\u4e2d\u95f4\u4ef6\u4e00\u6837\uff0c\u9664\u4e86\u8fd9\u4e9b\u56de\u8c03\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528<code style=\"color: #2c3e50;\">next('router')<\/code>\u6765\u7ed5\u8fc7\u5269\u4f59\u7684\u8def\u7531\u56de\u8c03\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u673a\u5236\u6765\u4e3a\u4e00\u4e2a\u8def\u7531\u8bbe\u7f6e\u4e00\u4e9b\u524d\u63d0\u6761\u4ef6\uff0c\u5982\u679c\u8bf7\u6c42\u6ca1\u6709\u6ee1\u8db3\u5f53\u524d\u8def\u7531\u7684\u5904\u7406\u6761\u4ef6\uff0c\u90a3\u4e48\u4f20\u9012\u63a7\u5236\u5230\u968f\u540e\u7684\u8def\u7531\u3002<\/p>\n<blockquote class=\"white-blockquote\" style=\"color: #2c3e50;\" data-anchor-id=\"yfkf\">\n<p style=\"font-weight: 300;\">\u672cAPI\u6587\u6863\u628a\u4f7f\u7528\u6bd4\u8f83\u591a\u7684HTTP\u65b9\u6cd5<code style=\"color: #2c3e50;\">app.get()<\/code>\uff0c<code style=\"color: #2c3e50;\">app.post<\/code>\uff0c<code style=\"color: #2c3e50;\">app.put()<\/code>\uff0c<code style=\"color: #2c3e50;\">app.delete()<\/code>\u4f5c\u4e3a\u4e00\u4e2a\u4e2a\u5355\u72ec\u7684\u9879\u8fdb\u884c\u8bf4\u660e\u3002\u7136\u800c\uff0c\u5176\u4ed6\u4e0a\u8ff0\u5217\u51fa\u7684\u65b9\u6cd5\u4ee5\u5b8c\u5168\u76f8\u540c\u7684\u65b9\u5f0f\u5de5\u4f5c\u3002<\/p>\n<\/blockquote>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"tby9\"><code style=\"color: #2c3e50;\">app.all()<\/code>\u662f\u4e00\u4e2a\u7279\u6b8a\u7684\u8def\u7531\u65b9\u6cd5\uff0c\u5b83\u4e0d\u5c5e\u4e8eHTTP\u534f\u8bae\u4e2d\u7684\u89c4\u5b9a\u7684\u65b9\u6cd5\u3002\u5b83\u4e3a\u4e00\u4e2a\u8def\u5f84\u52a0\u8f7d\u4e2d\u95f4\u4ef6\uff0c\u5176\u5bf9\u6240\u6709\u7684\u8bf7\u6c42\u65b9\u6cd5\u90fd\u6709\u6548\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">all<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/secret'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Accessing the secret section...'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ pass control to the next handler<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"appparamname-callback\" style=\"color: #2c3e50;\" data-anchor-id=\"yij4\">app.param([name], callback)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"efhr\">\u7ed9\u8def\u7531\u53c2\u6570\u6dfb\u52a0\u56de\u8c03\u89e6\u53d1\u5668\uff0c\u8fd9\u91cc\u7684<code style=\"color: #2c3e50;\">name<\/code>\u662f\u53c2\u6570\u540d\u6216\u8005\u53c2\u6570\u6570\u7ec4\uff0c<code style=\"color: #2c3e50;\">function<\/code>\u662f\u56de\u8c03\u65b9\u6cd5\u3002\u56de\u8c03\u65b9\u6cd5\u7684\u53c2\u6570\u6309\u5e8f\u662f\u8bf7\u6c42\u5bf9\u8c61\uff0c\u54cd\u5e94\u5bf9\u8c61\uff0c\u4e0b\u4e2a\u4e2d\u95f4\u4ef6\uff0c\u53c2\u6570\u503c\u548c\u53c2\u6570\u540d\u3002<br \/>\n\u5982\u679c<code style=\"color: #2c3e50;\">name<\/code>\u662f\u6570\u7ec4\uff0c\u4f1a\u6309\u7167\u5404\u4e2a\u53c2\u6570\u5728\u6570\u7ec4\u4e2d\u88ab\u58f0\u660e\u7684\u987a\u5e8f\u5c06\u56de\u8c03\u89e6\u53d1\u5668\u6ce8\u518c\u4e0b\u6765\u3002\u8fd8\u6709\uff0c\u5bf9\u4e8e\u9664\u4e86\u6700\u540e\u4e00\u4e2a\u53c2\u6570\u7684\u5176\u4ed6\u53c2\u6570\uff0c\u5728\u4ed6\u4eec\u7684\u56de\u8c03\u4e2d\u8c03\u7528<code style=\"color: #2c3e50;\">next()<\/code>\u6765\u8c03\u7528\u4e0b\u4e2a\u58f0\u660e\u53c2\u6570\u7684\u56de\u8c03\u3002\u5bf9\u4e8e\u6700\u540e\u4e00\u4e2a\u53c2\u6570\uff0c\u5728\u56de\u8c03\u4e2d\u8c03\u7528<code style=\"color: #2c3e50;\">next()<\/code>\u5c06\u8c03\u7528\u4f4d\u4e8e\u5f53\u524d\u5904\u7406\u8def\u7531\u4e2d\u7684\u4e0b\u4e00\u4e2a\u4e2d\u95f4\u4ef6\uff0c\u5982\u679c<code style=\"color: #2c3e50;\">name<\/code>\u53ea\u662f\u4e00\u4e2a<code style=\"color: #2c3e50;\">string<\/code>\u90a3\u5c31\u548c\u5b83\u662f\u4e00\u6837\u7684(\u5c31\u662f\u8bf4\u53ea\u6709\u4e00\u4e2a\u53c2\u6570\uff0c\u90a3\u4e48\u5c31\u662f\u6700\u540e\u4e00\u4e2a\u53c2\u6570\uff0c\u548c\u6570\u7ec4\u4e2d\u6700\u540e\u4e00\u4e2a\u53c2\u6570\u662f\u4e00\u6837\u7684)\u3002<br \/>\n\u4f8b\u5982\uff0c\u5f53<code style=\"color: #2c3e50;\">:user<\/code>\u51fa\u73b0\u5728\u8def\u7531\u8def\u5f84\u4e2d\uff0c\u4f60\u53ef\u4ee5\u6620\u5c04\u7528\u6237\u52a0\u8f7d\u7684\u903b\u8f91\u5904\u7406\u6765\u81ea\u52a8\u63d0\u4f9b<code style=\"color: #2c3e50;\">req.user<\/code>\u7ed9\u8fd9\u4e2a\u8def\u7531\uff0c\u6216\u8005\u5bf9\u8f93\u5165\u7684\u53c2\u6570\u8fdb\u884c\u9a8c\u8bc1\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">param<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'user'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> id<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"typ\" style=\"color: #660066;\">User<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">find<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">id<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">error<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> user<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">if<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">err<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">err<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">else<\/span><span class=\"kwd\" style=\"color: #000088;\">if<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">user<\/span><span class=\"pun\" style=\"color: #666600;\">){<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">user <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> user<\/span><span class=\"pun\" style=\"color: #666600;\">;<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><span class=\"kwd\" style=\"color: #000088;\">else<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">new<\/span><span class=\"typ\" style=\"color: #660066;\">Error<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'failed to load user'<\/span><span class=\"pun\" style=\"color: #666600;\">));<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"3x1j\">\u5bf9\u4e8e<code style=\"color: #2c3e50;\">Param<\/code>\u7684\u56de\u8c03\u5b9a\u4e49\u7684\u8def\u7531\u6765\u8bf4\uff0c\u4ed6\u4eec\u662f\u5c40\u90e8\u7684\u3002\u5b83\u4eec\u4e0d\u4f1a\u88ab\u6302\u8f7d\u7684app\u6216\u8005\u8def\u7531\u7ee7\u627f\u3002\u6240\u4ee5\uff0c\u5b9a\u4e49\u5728<code style=\"color: #2c3e50;\">app<\/code>\u4e0a\u7684<code style=\"color: #2c3e50;\">Param<\/code>\u56de\u8c03\u53ea\u6709\u662f\u5728<code style=\"color: #2c3e50;\">app<\/code>\u4e0a\u7684\u8def\u7531\u5177\u6709\u8fd9\u4e2a\u8def\u7531\u53c2\u6570\u65f6\u624d\u8d77\u4f5c\u7528\u3002<br \/>\n\u5728\u5b9a\u4e49<code style=\"color: #2c3e50;\">param<\/code>\u7684\u8def\u7531\u4e0a\uff0c<code style=\"color: #2c3e50;\">param<\/code>\u56de\u8c03\u90fd\u662f\u7b2c\u4e00\u4e2a\u88ab\u8c03\u7528\u7684\uff0c\u5b83\u4eec\u5728\u4e00\u4e2a\u8bf7\u6c42-\u54cd\u5e94\u5faa\u73af\u4e2d\u90fd\u4f1a\u88ab\u8c03\u7528\u4e00\u6b21\u5e76\u4e14\u53ea\u6709\u4e00\u6b21\uff0c\u5373\u4f7f\u591a\u4e2a\u8def\u7531\u90fd\u5339\u914d\uff0c\u5982\u4e0b\u9762\u7684\u4f8b\u5b50\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">param<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'id'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> id<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'CALLED ONLY ONCE'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/user\/:id'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'although this matches'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/user\/:id'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'and this mathces too'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">end<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"vwnc\">\u5f53<code style=\"color: #2c3e50;\">GET \/user\/42<\/code>\uff0c\u5f97\u5230\u4e0b\u9762\u7684\u7ed3\u679c:<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-log\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> CALLED ONLY ONCE<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-log\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> although <\/span><span class=\"kwd\" style=\"color: #000088;\">this<\/span><span class=\"pln\" style=\"color: #000000;\"> matches<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-log\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">and<\/span><span class=\"kwd\" style=\"color: #000088;\">this<\/span><span class=\"pln\" style=\"color: #000000;\"> matches too<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">param<\/span><span class=\"pun\" style=\"color: #666600;\">([<\/span><span class=\"str\" style=\"color: #008800;\">'id'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'page'<\/span><span class=\"pun\" style=\"color: #666600;\">],<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> value<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'CALLED ONLY ONCE with'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> value<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/user\/:id\/:page'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'although this matches'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/user\/:id\/:page'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'and this matches too'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">end<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"h423\">\u5f53\u6267\u884c<code style=\"color: #2c3e50;\">GET \/user\/42\/3<\/code>\uff0c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-log\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">CALLED ONLY ONCE <\/span><span class=\"kwd\" style=\"color: #000088;\">with<\/span><span class=\"lit\" style=\"color: #006666;\">42<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-log\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">CALLED ONLY ONCE <\/span><span class=\"kwd\" style=\"color: #000088;\">with<\/span><span class=\"lit\" style=\"color: #006666;\">3<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-log\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">although <\/span><span class=\"kwd\" style=\"color: #000088;\">this<\/span><span class=\"pln\" style=\"color: #000000;\"> matches<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-log\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">and<\/span><span class=\"kwd\" style=\"color: #000088;\">this<\/span><span class=\"pln\" style=\"color: #000000;\"> mathes too<\/span><\/code><\/li>\n<\/ol>\n<blockquote class=\"white-blockquote\" style=\"color: #2c3e50;\" data-anchor-id=\"8evf\">\n<p style=\"font-weight: 300;\">\u4e0b\u9762\u7ae0\u8282\u63cf\u8ff0\u7684<code style=\"color: #2c3e50;\">app.param(callback)<\/code>\u5728v4.11.0\u4e4b\u540e\u88ab\u5f03\u7528\u3002<\/p>\n<\/blockquote>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"m7nu\">\u901a\u8fc7\u53ea\u4f20\u9012\u4e00\u4e2a\u56de\u8c03\u53c2\u6570\u7ed9<code style=\"color: #2c3e50;\">app.param(name, callback)<\/code>\u65b9\u6cd5\uff0c<code style=\"color: #2c3e50;\">app.param(naem, callback)<\/code>\u65b9\u6cd5\u7684\u884c\u4e3a\u5c06\u88ab\u5b8c\u5168\u6539\u53d8\u3002\u8fd9\u4e2a\u56de\u8c03\u53c2\u6570\u662f\u5173\u4e8e<code style=\"color: #2c3e50;\">app.param(name, callback)<\/code>\u8be5\u5177\u6709\u600e\u6837\u7684\u884c\u4e3a\u7684\u4e00\u4e2a\u81ea\u5b9a\u4e49\u65b9\u6cd5\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u5fc5\u987b\u63a5\u53d7\u4e24\u4e2a\u53c2\u6570\u5e76\u4e14\u8fd4\u56de\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u3002<br \/>\n\u8fd9\u4e2a\u56de\u8c03\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u5c31\u662f\u9700\u8981\u6355\u83b7\u7684url\u7684\u53c2\u6570\u540d\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u53ef\u4ee5\u662f\u4efb\u4e00\u7684JavaScript\u5bf9\u8c61\uff0c\u5176\u53ef\u80fd\u5728\u5b9e\u73b0\u8fd4\u56de\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u65f6\u88ab\u4f7f\u7528\u3002<br \/>\n\u8fd9\u4e2a\u56de\u8c03\u65b9\u6cd5\u8fd4\u56de\u7684\u4e2d\u95f4\u4ef6\u51b3\u5b9a\u4e86\u5f53URL\u4e2d\u5305\u542b\u8fd9\u4e2a\u53c2\u6570\u65f6\u6240\u91c7\u53d6\u7684\u884c\u4e3a\u3002<br \/>\n\u5728\u4e0b\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c<code style=\"color: #2c3e50;\">app.param(name, callback)<\/code>\u53c2\u6570\u7b7e\u540d\u88ab\u4fee\u6539\u6210\u4e86<code style=\"color: #2c3e50;\">app.param(name, accessId)<\/code>\u3002\u66ff\u6362\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570\u540d\u548c\u56de\u8c03\uff0c<code style=\"color: #2c3e50;\">app.param()<\/code>\u73b0\u5728\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570\u540d\u548c\u4e00\u4e2a\u6570\u5b57\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> express <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> require<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'express'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> app <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> express<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">param<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">param<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> option<\/span><span class=\"pun\" style=\"color: #666600;\">){<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">return<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> val<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">if<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">val <\/span><span class=\"pun\" style=\"color: #666600;\">==<\/span><span class=\"pln\" style=\"color: #000000;\"> option<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">else<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">sendStatus<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">403<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">param<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'id'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"lit\" style=\"color: #006666;\">1337<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/user\/:id'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Ok'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">listen<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">3000<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">()<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Ready'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"0kgg\">\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code style=\"color: #2c3e50;\">app.param(name, callback)<\/code>\u53c2\u6570\u7b7e\u540d\u4fdd\u6301\u548c\u539f\u6765\u4e00\u6837\uff0c\u4f46\u662f\u66ff\u6362\u6210\u4e86\u4e00\u4e2a\u4e2d\u95f4\u4ef6\uff0c\u5b9a\u4e49\u4e86\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u6570\u636e\u7c7b\u578b\u68c0\u6d4b\u65b9\u6cd5\u6765\u68c0\u6d4b<code style=\"color: #2c3e50;\">user id<\/code>\u7684\u7c7b\u578b\u6b63\u786e\u6027\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">param<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">param<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> validator<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">return<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> val<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">if<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">validator<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">val<\/span><span class=\"pun\" style=\"color: #666600;\">))<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">else<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">sendStatus<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">403<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">param<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'id'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">candidate<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">return<\/span><span class=\"pun\" style=\"color: #666600;\">!<\/span><span class=\"pln\" style=\"color: #000000;\">isNaN<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">parseFloat<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">candidate<\/span><span class=\"pun\" style=\"color: #666600;\">))<\/span><span class=\"pun\" style=\"color: #666600;\">&amp;&amp;<\/span><span class=\"pln\" style=\"color: #000000;\"> isFinite<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">candidate<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<blockquote class=\"white-blockquote\" style=\"color: #2c3e50;\" data-anchor-id=\"2ut9\">\n<p style=\"font-weight: 300;\">\u5728\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\uff0c\u4e0d\u8981\u4f7f\u7528<code style=\"color: #2c3e50;\">.<\/code>\u3002\u4f8b\u5982\uff0c\u4f60\u4e0d\u80fd\u4f7f\u7528<code style=\"color: #2c3e50;\">\/user-.+\/<\/code>\u6765\u6355\u83b7<code style=\"color: #2c3e50;\">user-gami<\/code>\uff0c\u7528\u4f7f\u7528<code style=\"color: #2c3e50;\">[\\\\s\\\\S]<\/code>\u6216\u8005<code style=\"color: #2c3e50;\">[\\\\w\\\\&gt;W]<\/code>\u6765\u4ee3\u66ff(\u6b63\u5982<code style=\"color: #2c3e50;\">\/user-[\\\\s\\\\S]+\/<\/code>)\u3002<\/p>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/captures '1-a_6' but not '543-azser-sder'<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/[0-9]+-[[\\\\w]]*'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/captures '1-a_6' and '543-az(ser\"-sder' but not '5-a s'<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/[0-9]+-[[\\\\S]]*'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/captures all (equivalent to '.*')<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'[[\\\\s\\\\S]]*'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<\/blockquote>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"apppath\" style=\"color: #2c3e50;\" data-anchor-id=\"wkj5\">app.path()<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"hzl9\">\u901a\u8fc7\u8fd9\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u5f97\u5230<code style=\"color: #2c3e50;\">app<\/code>\u5178\u578b\u7684\u8def\u5f84\uff0c\u5176\u662f\u4e00\u4e2a<code style=\"color: #2c3e50;\">string<\/code>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> app <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> express<\/span><span class=\"pun\" style=\"color: #666600;\">()<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> blog <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> express<\/span><span class=\"pun\" style=\"color: #666600;\">()<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> blogAdmin <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> express<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/blog'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> blog<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/admin'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> blogAdmin<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">path<\/span><span class=\"pun\" style=\"color: #666600;\">());<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ ''<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">blog<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">path<\/span><span class=\"pun\" style=\"color: #666600;\">());<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ '\/blog'<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">blogAdmin<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">path<\/span><span class=\"pun\" style=\"color: #666600;\">());<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ '\/blog\/admin'<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"ta23\">\u5982\u679c<code style=\"color: #2c3e50;\">app<\/code>\u6302\u8f7d\u5f88\u590d\u6742\u4e0b\uff0c\u90a3\u4e48\u8fd9\u4e2a\u65b9\u6cd5\u7684\u884c\u4e3a\u4e5f\u4f1a\u5f88\u590d\u6742\uff1a\u4e00\u79cd\u66f4\u597d\u7528\u7684\u65b9\u5f0f\u662f\u4f7f\u7528<code style=\"color: #2c3e50;\">req.baseUrl<\/code>\u6765\u83b7\u5f97\u8fd9\u4e2aapp\u7684\u5178\u578b\u8def\u5f84\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"apppostpath-callback-callback\" style=\"color: #2c3e50;\" data-anchor-id=\"kec6\">app.post(path, callback, [callback &#8230;])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"0qhh\">\u8def\u7531<code style=\"color: #2c3e50;\">HTTP POST<\/code>\u8bf7\u6c42\u5230\u6709\u7279\u6b8a\u56de\u8c03\u7684\u7279\u6b8a\u8def\u5f84\u3002\u83b7\u53d6\u66f4\u591a\u7684\u4fe1\u606f\uff0c\u53ef\u4ee5\u67e5\u9605<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/guide\/routing.html\" target=\"_blank\">routing guide<\/a>\u3002<br \/>\n\u4f60\u53ef\u4ee5\u63d0\u4f9b\u591a\u4e2a\u56de\u8c03\u51fd\u6570\uff0c\u5b83\u4eec\u7684\u884c\u4e3a\u548c\u4e2d\u95f4\u4ef6\u4e00\u6837\uff0c\u9664\u4e86\u8fd9\u4e9b\u56de\u8c03\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528<code style=\"color: #2c3e50;\">next('router')<\/code>\u6765\u7ed5\u8fc7\u5269\u4f59\u7684\u8def\u7531\u56de\u8c03\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u673a\u5236\u6765\u4e3a\u4e00\u4e2a\u8def\u7531\u8bbe\u7f6e\u4e00\u4e9b\u524d\u63d0\u6761\u4ef6\uff0c\u5982\u679c\u8bf7\u6c42\u6ca1\u80fd\u6ee1\u8db3\u5f53\u524d\u8def\u7531\u7684\u5904\u7406\u6761\u4ef6\uff0c\u90a3\u4e48\u4f20\u9012\u63a7\u5236\u5230\u968f\u540e\u7684\u8def\u7531\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">post<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'POST request to homepage'<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"appputpath-callback-callback\" style=\"color: #2c3e50;\" data-anchor-id=\"fpti\">app.put(path, callback, [callback &#8230;])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"pxee\">\u8def\u7531<code style=\"color: #2c3e50;\">HTTP PUT<\/code>\u8bf7\u6c42\u5230\u6709\u7279\u6b8a\u56de\u8c03\u7684\u7279\u6b8a\u8def\u5f84\u3002\u83b7\u53d6\u66f4\u591a\u7684\u4fe1\u606f\uff0c\u53ef\u4ee5\u67e5\u9605<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/guide\/routing.html\" target=\"_blank\">routing guide<\/a>\u3002<br \/>\n\u4f60\u53ef\u4ee5\u63d0\u4f9b\u591a\u4e2a\u56de\u8c03\u51fd\u6570\uff0c\u5b83\u4eec\u7684\u884c\u4e3a\u548c\u4e2d\u95f4\u4ef6\u4e00\u6837\uff0c\u9664\u4e86\u8fd9\u4e9b\u56de\u8c03\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528<code style=\"color: #2c3e50;\">next('router')<\/code>\u6765\u7ed5\u8fc7\u5269\u4f59\u7684\u8def\u7531\u56de\u8c03\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u673a\u5236\u6765\u4e3a\u4e00\u4e2a\u8def\u7531\u8bbe\u7f6e\u4e00\u4e9b\u524d\u63d0\u6761\u4ef6\uff0c\u5982\u679c\u8bf7\u6c42\u6ca1\u80fd\u6ee1\u8db3\u5f53\u524d\u8def\u7531\u7684\u5904\u7406\u6761\u4ef6\uff0c\u90a3\u4e48\u4f20\u9012\u63a7\u5236\u5230\u968f\u540e\u7684\u8def\u7531\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">put<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'PUT request to homepage'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"apprenderview-locals-callback\" style=\"color: #2c3e50;\" data-anchor-id=\"m8fs\">app.render(view, [locals], callback)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"uxit\">\u901a\u8fc7<code style=\"color: #2c3e50;\">callback<\/code>\u56de\u8c03\u8fd4\u56de\u4e00\u4e2a<code style=\"color: #2c3e50;\">view<\/code>\u6e32\u67d3\u4e4b\u540e\u5f97\u5230\u7684HTML\u6587\u672c\u3002\u5b83\u53ef\u4ee5\u63a5\u53d7\u4e00\u4e2a\u53ef\u9009\u7684\u53c2\u6570\uff0c\u53ef\u9009\u53c2\u6570\u5305\u542b\u4e86\u8fd9\u4e2a<code style=\"color: #2c3e50;\">view<\/code>\u9700\u8981\u7528\u5230\u7684\u672c\u5730\u6570\u636e\u3002\u8fd9\u4e2a\u65b9\u6cd5\u7c7b\u4f3c\u4e8e<code style=\"color: #2c3e50;\">res.render()<\/code>\uff0c\u9664\u4e86\u5b83\u4e0d\u80fd\u628a\u6e32\u67d3\u5f97\u5230\u7684HTML\u6587\u672c\u53d1\u9001\u7ed9\u5ba2\u6237\u7aef\u3002<\/p>\n<blockquote class=\"white-blockquote\" style=\"color: #2c3e50;\" data-anchor-id=\"h9ji\">\n<p style=\"font-weight: 300;\">\u5c06<code style=\"color: #2c3e50;\">app.render()<\/code>\u5f53\u4f5c\u662f\u53ef\u4ee5\u751f\u6210\u6e32\u67d3\u89c6\u56fe\u5b57\u7b26\u4e32\u7684\u5de5\u5177\u65b9\u6cd5\u3002\u5728<code style=\"color: #2c3e50;\">res.render()<\/code>\u5185\u90e8\uff0c\u5c31\u662f\u4f7f\u7528\u7684<code style=\"color: #2c3e50;\">app.render()<\/code>\u6765\u6e32\u67d3\u89c6\u56fe\u3002<\/p>\n<p style=\"font-weight: 300;\">\u5982\u679c\u4f7f\u80fd\u4e86\u89c6\u56fe\u7f13\u5b58\uff0c\u90a3\u4e48\u672c\u5730\u53d8\u91cf\u7f13\u5b58\u5c31\u4f1a\u4fdd\u7559\u3002\u5982\u679c\u4f60\u60f3\u5728\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\u7f13\u5b58\u89c6\u56fe\uff0c\u8bbe\u7f6e\u5b83\u4e3a<code style=\"color: #2c3e50;\">true<\/code>\u3002\u5728\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u89c6\u56fe\u7f13\u5b58\u9ed8\u8ba4\u662f\u6253\u5f00\u7684\u3002<\/p>\n<\/blockquote>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">render<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'email'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">err<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> html<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ ...<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">render<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'email'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><span class=\"pln\" style=\"color: #000000;\">name<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'Tobi'<\/span><span class=\"pun\" style=\"color: #666600;\">},<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">err<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> html<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ ...<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"approutepath\" style=\"color: #2c3e50;\" data-anchor-id=\"0kbw\">app.route(path)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"ec88\">\u8fd4\u56de\u4e00\u4e2a\u5355\u4f8b\u6a21\u5f0f\u7684\u8def\u7531\u7684\u5b9e\u4f8b\uff0c\u4e4b\u540e\u4f60\u53ef\u4ee5\u5728\u5176\u4e0a\u65bd\u52a0\u5404\u79cdHTTP\u52a8\u4f5c\u7684\u4e2d\u95f4\u4ef6\u3002\u4f7f\u7528<code style=\"color: #2c3e50;\">app.route()<\/code>\u6765\u907f\u514d\u91cd\u590d\u8def\u7531\u540d\u5b57(\u56e0\u6b64\u9519\u5b57\u9519\u8bef)&#8211;\u8bf4\u7684\u610f\u601d\u5e94\u8be5\u662f\u4f7f\u7528<code style=\"color: #2c3e50;\">app.router()<\/code>\u8fd9\u4e2a\u5355\u4f8b\u65b9\u6cd5\u6765\u907f\u514d\u540c\u4e00\u4e2a\u8def\u5f84\u591a\u4e2a\u8def\u7531\u5b9e\u4f8b\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> app <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> express<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">route<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/events'<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">all<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ runs for all HTTP verbs first<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ think of it as route specific middleware!<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">})<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">json<\/span><span class=\"pun\" style=\"color: #666600;\">(...);<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">})<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">post<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ maybe add a new event...<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">})<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"appsetname-value\" style=\"color: #2c3e50;\" data-anchor-id=\"ei3n\">app.set(name, value)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"trza\">\u7ed9<code style=\"color: #2c3e50;\">name<\/code>\u8bbe\u7f6e\u9879\u8d4b<code style=\"color: #2c3e50;\">value<\/code>\u503c\uff0c<code style=\"color: #2c3e50;\">name<\/code>\u662f<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#app.settings.table\" target=\"_blank\">app settings table<\/a>\u4e2d\u5c5e\u6027\u7684\u4e00\u9879\u3002<br \/>\n\u5bf9\u4e8e\u4e00\u4e2a\u7c7b\u578b\u662f\u5e03\u5c14\u578b\u7684\u5c5e\u6027\u8c03\u7528<code style=\"color: #2c3e50;\">app.set('foo', ture)<\/code>\u7b49\u4ef7\u4e8e\u8c03\u7528<code style=\"color: #2c3e50;\">app.enable('foo')<\/code>\u3002\u540c\u6837\u7684\uff0c\u8c03\u7528<code style=\"color: #2c3e50;\">app.set('foo', false)<\/code>\u7b49\u4ef7\u4e8e\u8c03\u7528<code style=\"color: #2c3e50;\">app.disable('foo')<\/code>\u3002<br \/>\n\u53ef\u4ee5\u4f7f\u7528<code style=\"color: #2c3e50;\">app.get()<\/code>\u6765\u53d6\u5f97\u8bbe\u7f6e\u7684\u503c\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">set<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'title'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'My Site'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'title'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ 'My Site'<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"om24\"><strong style=\"font-weight: bold;\">Application Settings<\/strong><br \/>\n\u5982\u679c<code style=\"color: #2c3e50;\">name<\/code>\u662f\u7a0b\u5e8f\u8bbe\u7f6e\u4e4b\u4e00\uff0c\u5b83\u5c06\u5f71\u54cd\u5230\u7a0b\u5e8f\u7684\u884c\u4e3a\u3002\u4e0b\u8fb9\u5217\u51fa\u4e86\u7a0b\u5e8f\u4e2d\u7684\u8bbe\u7f6e\u3002<\/p>\n<table class=\"table table-striped-white table-bordered\" style=\"color: #2c3e50;\" data-anchor-id=\"bmmc\">\n<thead>\n<tr>\n<th style=\"font-weight: bold;\">Property<\/th>\n<th style=\"font-weight: bold;\">Type<\/th>\n<th style=\"font-weight: bold;\">Value<\/th>\n<th style=\"font-weight: bold;\">Default<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>case sensitive routing<\/td>\n<td>Boolean<\/td>\n<td>\u542f\u7528\u533a\u5206\u5927\u5c0f\u5199\u3002<\/td>\n<td>\u4e0d\u542f\u7528\u3002\u5bf9<code style=\"color: #2c3e50;\">\/Foo<\/code>\u548c<code style=\"color: #2c3e50;\">\/foo<\/code>\u5904\u7406\u662f\u4e00\u6837\u3002<\/td>\n<\/tr>\n<tr>\n<td>env<\/td>\n<td>String<\/td>\n<td>\u73af\u5883\u6a21\u578b\u3002<\/td>\n<td>process.env.NODE_ENV(NODE_ENV\u73af\u5883\u53d8\u91cf)\u6216\u8005&#8221;development&#8221;<\/td>\n<\/tr>\n<tr>\n<td>etag<\/td>\n<td>Varied<\/td>\n<td>\u8bbe\u7f6e<code style=\"color: #2c3e50;\">ETag<\/code>\u54cd\u5e94\u5934\u3002\u53ef\u53d6\u7684\u503c\uff0c\u53ef\u4ee5\u67e5\u9605<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#etag.options.table\" target=\"_blank\">etag options table<\/a>\u3002\u66f4\u591a\u5173\u4e8e<a style=\"color: #0088cc;\" href=\"http:\/\/en.wikipedia.org\/wiki\/HTTP_ETag\" target=\"_blank\">HTTP ETag header<\/a>\u3002<\/td>\n<td>weak<\/td>\n<\/tr>\n<tr>\n<td>jsonp callback name<\/td>\n<td>String<\/td>\n<td>\u6307\u5b9a\u9ed8\u8ba4JSONP\u56de\u8c03\u7684\u540d\u79f0\u3002<\/td>\n<td>?callback=<\/td>\n<\/tr>\n<tr>\n<td>json replacer<\/td>\n<td>String<\/td>\n<td>JSON\u66ff\u4ee3\u54c1\u56de\u8c03<\/td>\n<td>null<\/td>\n<\/tr>\n<tr>\n<td>json spaces<\/td>\n<td>Number<\/td>\n<td>\u5f53\u8bbe\u7f6e\u4e86\u8fd9\u4e2a\u503c\u540e\uff0c\u53d1\u9001\u7f29\u8fdb\u7a7a\u683c\u7f8e\u5316\u8fc7\u7684JSON\u5b57\u7b26\u4e32\u3002<\/td>\n<td>Disabled<\/td>\n<\/tr>\n<tr>\n<td>query parser<\/td>\n<td>Varied<\/td>\n<td>\u8bbe\u7f6e\u503c\u4e3a<code style=\"color: #2c3e50;\">false<\/code>\u6765\u7981\u7528<code style=\"color: #2c3e50;\">query parser<\/code>\uff0c\u6216\u8005\u8bbe\u7f6e<code style=\"color: #2c3e50;\">simple<\/code>,<code style=\"color: #2c3e50;\">extended<\/code>\uff0c\u4e5f\u53ef\u4ee5\u81ea\u5df1\u5b9e\u73b0<code style=\"color: #2c3e50;\">query string<\/code>\u89e3\u6790\u51fd\u6570\u3002<code style=\"color: #2c3e50;\">simple<\/code>\u57fa\u4e8e<code style=\"color: #2c3e50;\">Node<\/code>\u539f\u751f\u7684<code style=\"color: #2c3e50;\">query<\/code>\u89e3\u6790\uff0c<a style=\"color: #0088cc;\" href=\"http:\/\/nodejs.org\/api\/querystring.html\" target=\"_blank\">querystring<\/a>\u3002<\/td>\n<td>&#8220;extend&#8221;<\/td>\n<\/tr>\n<tr>\n<td>strict routing<\/td>\n<td>Boolean<\/td>\n<td>\u542f\u7528\u4e25\u683c\u7684\u8def\u7531\u3002<\/td>\n<td>\u4e0d\u542f\u7528\u3002\u5bf9<code style=\"color: #2c3e50;\">\/foo<\/code>\u548c<code style=\"color: #2c3e50;\">\/foo\/<\/code>\u7684\u8def\u7531\u5904\u7406\u662f\u4e00\u6837\u3002<\/td>\n<\/tr>\n<tr>\n<td>subdomain offset<\/td>\n<td>Number<\/td>\n<td>\u7528\u6765\u5220\u9664\u8bbf\u95ee\u5b50\u57df\u7684\u4e3b\u673a\u70b9\u5206\u90e8\u5206\u7684\u4e2a\u6570<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>trust proxy<\/td>\n<td>Varied<\/td>\n<td>\u6307\u793a<code style=\"color: #2c3e50;\">app<\/code>\u5728\u4e00\u4e2a\u53cd\u5411\u4ee3\u7406\u7684\u540e\u9762\uff0c\u4f7f\u7528<code style=\"color: #2c3e50;\">x-Forwarded-*<\/code>\u6765\u786e\u5b9a\u8fde\u63a5\u548c\u5ba2\u6237\u7aef\u7684IP\u5730\u5740\u3002\u6ce8\u610f:<code style=\"color: #2c3e50;\">X-Forwarded-*<\/code>\u5934\u90e8\u5f88\u5bb9\u6613\u88ab\u6b3a\u9a97\uff0c\u6240\u6709\u68c0\u6d4b\u5ba2\u6237\u7aef\u7684IP\u5730\u5740\u662f\u9760\u4e0d\u4f4f\u7684\u3002<code style=\"color: #2c3e50;\">trust proxy<\/code>\u9ed8\u8ba4\u4e0d\u542f\u7528\u3002\u5f53\u542f\u7528\u65f6\uff0cExpress\u5c1d\u8bd5\u901a\u8fc7\u524d\u7aef\u4ee3\u7406\u6216\u8005\u4e00\u7cfb\u5217\u4ee3\u7406\u6765\u83b7\u53d6\u5df2\u8fde\u63a5\u7684\u5ba2\u6237\u7aefIP\u5730\u5740\u3002<code style=\"color: #2c3e50;\">req.ips<\/code>\u5c5e\u6027\u5305\u542b\u4e86\u5df2\u8fde\u63a5\u5ba2\u6237\u7aefIP\u5730\u5740\u7684\u4e00\u4e2a\u6570\u7ec4\u3002\u4e3a\u4e86\u542f\u52a8\u5b83\uff0c\u9700\u8981\u8bbe\u7f6e\u5728\u4e0b\u9762<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#trust.proxy.options.table\" target=\"_blank\">trust proxy options table<\/a>\u4e2d\u5b9a\u4e49\u7684\u503c\u3002<code style=\"color: #2c3e50;\">trust proxy<\/code>\u7684\u8bbe\u7f6e\u5b9e\u73b0\u4f7f\u7528\u4e86<code style=\"color: #2c3e50;\">proxy-addr<\/code>\u5305\u3002\u5982\u679c\u60f3\u83b7\u5f97\u66f4\u591a\u7684\u4fe1\u606f\uff0c\u53ef\u4ee5\u67e5\u9605\u5b83\u7684\u6587\u6863<\/td>\n<td>Disable<\/td>\n<\/tr>\n<tr>\n<td>views<\/td>\n<td>String or Array<\/td>\n<td><code style=\"color: #2c3e50;\">view<\/code>\u6240\u5728\u7684\u76ee\u5f55\u6216\u8005\u76ee\u5f55\u6570\u7ec4\u3002\u5982\u679c\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u5c06\u6309\u5728\u6570\u7ec4\u4e2d\u7684\u987a\u5e8f\u6765\u67e5\u627e<code style=\"color: #2c3e50;\">view<\/code>\u3002<\/td>\n<td>process.cwd() + &#8216;\/views&#8217;<\/td>\n<\/tr>\n<tr>\n<td>view cache<\/td>\n<td>Boolean<\/td>\n<td>\u542f\u7528\u89c6\u56fe\u6a21\u677f\u7f16\u8bd1\u7f13\u5b58\u3002<\/td>\n<td>\u5728\u751f\u6210\u73af\u5883\u9ed8\u8ba4\u5f00\u542f\u3002<\/td>\n<\/tr>\n<tr>\n<td>view engine<\/td>\n<td>String<\/td>\n<td>\u7701\u7565\u65f6\uff0c\u9ed8\u8ba4\u7684\u5f15\u64ce\u88ab\u6269\u5c55\u4f7f\u7528\u3002<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>x-powered-by<\/td>\n<td>Boolean<\/td>\n<td>\u542f\u7528<code style=\"color: #2c3e50;\">X-Powered-By:Express<\/code>HTTP\u5934\u90e8<\/td>\n<td>true<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"ao1i\"><strong style=\"font-weight: bold;\">Options for\u00a0<code style=\"color: #2c3e50;\">trust proxy<\/code>\u00a0settings<\/strong><br \/>\n\u67e5\u9605<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/guide\/behind-proxies.html\" target=\"_blank\">Express behind proxies<\/a>\u6765\u83b7\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n<table class=\"table table-striped-white table-bordered\" style=\"color: #2c3e50;\" data-anchor-id=\"f6ow\">\n<thead>\n<tr>\n<th style=\"font-weight: bold;\">Type<\/th>\n<th style=\"font-weight: bold;\">Value<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Boolean<\/td>\n<td>\u5982\u679c\u4e3a<code style=\"color: #2c3e50;\">true<\/code>\uff0c\u5ba2\u6237\u7aef\u7684IP\u5730\u5740\u4f5c\u4e3a<code style=\"color: #2c3e50;\">X-Forwarded-*<\/code>\u5934\u90e8\u7684\u6700\u5de6\u8fb9\u7684\u6761\u76ee\u3002\u5982\u679c\u4e3a<code style=\"color: #2c3e50;\">false<\/code>\uff0c\u53ef\u4ee5\u7406\u89e3\u4e3a<code style=\"color: #2c3e50;\">app<\/code>\u76f4\u63a5\u4e0e\u82f1\u7279\u7f51\u76f4\u8fde\uff0c\u5ba2\u6237\u7aef\u7684IP\u5730\u5740\u884d\u751f\u81ea<code style=\"color: #2c3e50;\">req.connection.remoteAddress<\/code>\u3002<code style=\"color: #2c3e50;\">false<\/code>\u662f\u9ed8\u8ba4\u8bbe\u7f6e\u3002<\/td>\n<\/tr>\n<tr>\n<td>IP addresses<\/td>\n<td>\u4e00\u4e2aIP\u5730\u5740\uff0c\u5b50\u7f51\uff0c\u6216\u8005\u4e00\u7ec4IP\u5730\u5740\uff0c\u548c\u59d4\u6258\u5b50\u7f51\u3002\u4e0b\u9762\u5217\u51fa\u7684\u662f\u4e00\u4e2a\u9884\u5148\u914d\u7f6e\u7684\u5b50\u7f51\u540d\u5217\u8868\u3002<\/p>\n<ul>\n<li>loopback &#8211;\u00a0<code style=\"color: #2c3e50;\">127.0.0.1\/8<\/code>,\u00a0<code style=\"color: #2c3e50;\">::1\/128<\/code><\/li>\n<li>linklocal &#8211;\u00a0<code style=\"color: #2c3e50;\">169.254.0.0\/16<\/code>,\u00a0<code style=\"color: #2c3e50;\">fe80::\/10<\/code><\/li>\n<li>uniquelocal &#8211;\u00a0<code style=\"color: #2c3e50;\">10.0.0.0\/8<\/code>,\u00a0<code style=\"color: #2c3e50;\">172.16.0.0\/12<\/code>,\u00a0<code style=\"color: #2c3e50;\">192.168.0.0\/16<\/code>,\u00a0<code style=\"color: #2c3e50;\">fc00::\/7<\/code><\/li>\n<\/ul>\n<p>\u4f7f\u7528\u4e0b\u9762\u65b9\u6cd5\u4e2d\u7684\u4efb\u4f55\u4e00\u79cd\u6765\u8bbe\u7f6eIP\u5730\u5740:<\/p>\n<pre class=\"language-javascript\"><code class=\"language-javascript\" style=\"color: inherit;\">app<span class=\"token punctuation\">.<\/span><span class=\"token keyword\">set<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'trust proxy'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">'loopback'<\/span><span class=\"token punctuation\">)<\/span> \/\/ specify a single subnet\r\n  app<span class=\"token punctuation\">.<\/span><span class=\"token keyword\">set<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'trust proxy'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">'loopback, 123.123.123.123'<\/span><span class=\"token punctuation\">)<\/span> \/\/ specify a subnet and an address\r\n  app<span class=\"token punctuation\">.<\/span><span class=\"token keyword\">set<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'trust proxy'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">'loopback, linklocal, uniquelocal'<\/span><span class=\"token punctuation\">)<\/span> \/\/ specify multiple subnets as CSV\r\n  app<span class=\"token punctuation\">.<\/span><span class=\"token keyword\">set<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'trust proxy'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">'loopback'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">'linklocal'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">'uniquelocal'<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span> \/\/ specify multiple subnets as an array<\/code><\/pre>\n<p>\u5f53\u6307\u5b9aIP\u5730\u5740\u4e4b\u540e, \u8fd9\u4e2aIP\u5730\u5740\u6216\u5b50\u7f51\u4f1a\u88ab\u8bbe\u7f6e\u4e86\u8fd9\u4e2aIP\u5730\u5740\u6216\u5b50\u7f51\u7684`app`\u6392\u9664\u5728\u5916, \u6700\u9760\u8fd1\u7a0b\u5e8f\u670d\u52a1\u7684\u6ca1\u6709\u59d4\u6258\u7684\u5730\u5740\u5c06\u88ab\u770b\u505a\u5ba2\u6237\u7aefIP\u5730\u5740\u3002<\/td>\n<\/tr>\n<tr>\n<td>Number<\/td>\n<td>\u4fe1\u4efb\u4ece\u53cd\u5411\u4ee3\u7406\u5230app\u4e2d\u95f4\u5c0f\u4e8e\u7b49\u4e8en\u8df3\u7684\u8fde\u63a5\u4e3a\u5ba2\u6237\u7aef\u3002<\/td>\n<\/tr>\n<tr>\n<td>Function<\/td>\n<td>\u5ba2\u6237\u81ea\u5b9a\u4e49\u59d4\u6258\u4ee3\u7406\u4fe1\u4efb\u673a\u5236\u3002\u5982\u679c\u4f60\u4f7f\u7528\u8fd9\u4e2a\uff0c\u8bf7\u786e\u4fdd\u4f60\u81ea\u5df1\u77e5\u9053\u4f60\u5728\u5e72\u4ec0\u4e48\u3002<\/p>\n<pre class=\"language-javascript\"><code class=\"language-javascript\" style=\"color: inherit;\">app<span class=\"token punctuation\">.<\/span><span class=\"token keyword\">set<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'trust proxy'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token punctuation\">(<\/span>ip<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>ip <span class=\"token operator\">===<\/span> <span class=\"token string\">'127.0.0.1'<\/span> <span class=\"token operator\">||<\/span> ip <span class=\"token operator\">===<\/span> <span class=\"token string\">'123.123.123.123'<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token keyword\">true<\/span><span class=\"token punctuation\">;<\/span> \/\/ trusted IPs\r\n    <span class=\"token keyword\">else<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token keyword\">false<\/span><span class=\"token punctuation\">;<\/span>\r\n  <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><\/code><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"t2jn\"><strong style=\"font-weight: bold;\">Options for\u00a0<code style=\"color: #2c3e50;\">etag<\/code>\u00a0settings<\/strong><br \/>\n<code style=\"color: #2c3e50;\">ETag<\/code>\u529f\u80fd\u7684\u5b9e\u73b0\u4f7f\u7528\u4e86<a style=\"color: #0088cc;\" href=\"https:\/\/www.npmjs.org\/package\/etag\" target=\"_blank\">etag<\/a>\u5305\u3002\u5982\u679c\u4f60\u9700\u8981\u83b7\u5f97\u66f4\u591a\u7684\u4fe1\u606f\uff0c\u4f60\u53ef\u4ee5\u67e5\u9605\u5b83\u7684\u6587\u6863\u3002<\/p>\n<table class=\"table table-striped-white table-bordered\" style=\"color: #2c3e50;\" data-anchor-id=\"8ccd\">\n<thead>\n<tr>\n<th style=\"font-weight: bold;\">Type<\/th>\n<th style=\"font-weight: bold;\">Value<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Boolean<\/td>\n<td>\u8bbe\u7f6e\u4e3a<code style=\"color: #2c3e50;\">true<\/code>\uff0c\u542f\u7528weak ETag\u3002\u8fd9\u4e2a\u662f\u9ed8\u8ba4\u8bbe\u7f6e\u3002\u8bbe\u7f6e<code style=\"color: #2c3e50;\">false<\/code>\uff0c\u7981\u7528\u6240\u6709\u7684ETag\u3002<\/td>\n<\/tr>\n<tr>\n<td>String<\/td>\n<td>\u5982\u679c\u662f<code style=\"color: #2c3e50;\">strong<\/code>\uff0c\u4f7f\u80fdstrong ETag\u3002\u5982\u679c\u662f<code style=\"color: #2c3e50;\">weak<\/code>\uff0c\u542f\u7528<code style=\"color: #2c3e50;\">weak<\/code>\u00a0ETag\u3002<\/td>\n<\/tr>\n<tr>\n<td>Function<\/td>\n<td>\u5ba2\u6237\u81ea\u5b9a\u4e49`ETag`\u65b9\u6cd5\u7684\u5b9e\u73b0. \u5982\u679c\u4f60\u4f7f\u7528\u8fd9\u4e2a\uff0c\u8bf7\u786e\u4fdd\u4f60\u81ea\u5df1\u77e5\u9053\u4f60\u5728\u5e72\u4ec0\u4e48\u3002<\/p>\n<pre class=\"language-javascript\"><code class=\"language-javascript\" style=\"color: inherit;\">app<span class=\"token punctuation\">.<\/span><span class=\"token keyword\">set<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'etag'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token punctuation\">(<\/span>body<span class=\"token punctuation\">,<\/span> encoding<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token keyword\">return<\/span> <span class=\"token function\">generateHash<span class=\"token punctuation\">(<\/span><\/span>body<span class=\"token punctuation\">,<\/span> encoding<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> \/\/ consider the function is defined\r\n  <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><\/code><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"appusepath-function-function\" style=\"color: #2c3e50;\" data-anchor-id=\"e339\">app.use([path,], function [, function&#8230;])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"hmnr\">\u6302\u8f7d<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/guide\/using-middleware.html\" target=\"_blank\">\u4e2d\u95f4\u4ef6<\/a>\u65b9\u6cd5\u5230\u8def\u5f84\u4e0a\u3002\u5982\u679c\u8def\u5f84\u672a\u6307\u5b9a\uff0c\u90a3\u4e48\u9ed8\u8ba4\u4e3a&#8221;\/&#8221;\u3002<\/p>\n<blockquote class=\"white-blockquote\" style=\"color: #2c3e50;\" data-anchor-id=\"81kq\">\n<p style=\"font-weight: 300;\">\u4e00\u4e2a\u8def\u7531\u5c06\u5339\u914d\u4efb\u4f55\u8def\u5f84\u5982\u679c\u8fd9\u4e2a\u8def\u5f84\u4ee5\u8fd9\u4e2a\u8def\u7531\u8bbe\u7f6e\u8def\u5f84\u540e\u7d27\u8ddf\u7740&#8221;\/&#8221;\u3002\u6bd4\u5982\uff1a<code style=\"color: #2c3e50;\">app.use('\/appale', ...)<\/code>\u5c06\u5339\u914d&#8221;\/apple&#8221;\uff0c&#8221;\/apple\/images&#8221;\uff0c&#8221;\/apple\/images\/news&#8221;\u7b49\u3002<\/p>\n<p style=\"font-weight: 300;\">\u4e2d\u95f4\u4ef6\u4e2d\u7684<code style=\"color: #2c3e50;\">req.originalUrl<\/code>\u662f<code style=\"color: #2c3e50;\">req.baseUrl<\/code>\u548c<code style=\"color: #2c3e50;\">req.path<\/code>\u7684\u7ec4\u5408\uff0c\u5982\u4e0b\u9762\u7684\u4f8b\u5b50\u6240\u793a\u3002<\/p>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/admin'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ GET 'http:\/\/www.example.com\/admin\/new'<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">originalUrl<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ '\/admin\/new'<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">baseUrl<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ '\/admin'<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">path<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ '\/new'<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<\/blockquote>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"cwo0\">\u5728\u4e00\u4e2a\u8def\u5f84\u4e0a\u6302\u8f7d\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u4e4b\u540e\uff0c\u6bcf\u5f53\u8bf7\u6c42\u7684\u8def\u5f84\u7684\u524d\u7f00\u90e8\u5206\u5339\u914d\u4e86\u8fd9\u4e2a\u8def\u7531\u8def\u5f84\uff0c\u90a3\u4e48\u8fd9\u4e2a\u4e2d\u95f4\u4ef6\u5c31\u4f1a\u88ab\u6267\u884c\u3002<br \/>\n\u7531\u4e8e\u9ed8\u8ba4\u7684\u8def\u5f84\u4e3a<code style=\"color: #2c3e50;\">\/<\/code>\uff0c\u4e2d\u95f4\u4ef6\u6302\u8f7d\u6ca1\u6709\u6307\u5b9a\u8def\u5f84\uff0c\u90a3\u4e48\u5bf9\u4e8e\u6bcf\u4e2a\u8bf7\u6c42\uff0c\u8fd9\u4e2a\u4e2d\u95f4\u4ef6\u90fd\u4f1a\u88ab\u6267\u884c\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ this middleware will be executed for every request to the app.<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Time: %d'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"typ\" style=\"color: #660066;\">Date<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">now<\/span><span class=\"pun\" style=\"color: #666600;\">());<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"04ga\">\u4e2d\u95f4\u4ef6\u65b9\u6cd5\u662f\u987a\u5e8f\u5904\u7406\u7684\uff0c\u6240\u4ee5\u4e2d\u95f4\u4ef6\u5305\u542b\u7684\u987a\u5e8f\u662f\u5f88\u91cd\u8981\u7684\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ this middleware will not allow the request to go beyond it<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Hello World'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ this middleware will never reach this route<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Welcome'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"dw4g\">\u8def\u5f84\u53ef\u4ee5\u662f\u4ee3\u8868\u8def\u5f84\u7684\u4e00\u4e32\u5b57\u7b26\uff0c\u4e00\u4e2a\u8def\u5f84\u6a21\u5f0f\uff0c\u4e00\u4e2a\u5339\u914d\u8def\u5f84\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u6216\u8005\u4ed6\u4eec\u7684\u4e00\u7ec4\u96c6\u5408\u3002<\/p>\n<blockquote class=\"white-blockquote\" style=\"color: #2c3e50;\" data-anchor-id=\"jtg7\">\n<p style=\"font-weight: 300;\">\u4e0b\u9762\u662f\u8def\u5f84\u7684\u7b80\u5355\u7684\u4f8b\u5b50\u3002<\/p>\n<\/blockquote>\n<table class=\"table table-striped-white table-bordered\" style=\"color: #2c3e50;\" data-anchor-id=\"b21o\">\n<thead>\n<tr>\n<th style=\"font-weight: bold;\">Type<\/th>\n<th style=\"font-weight: bold;\">Example<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Path<\/td>\n<td>\n<pre class=\"language-javascript\"><code class=\"language-javascript\" style=\"color: inherit;\">\/\/ will match paths starting with \/abcd\r\napp<span class=\"token punctuation\">.<\/span><span class=\"token function\">use<span class=\"token punctuation\">(<\/span><\/span><span class=\"token string\">'\/abcd'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token punctuation\">(<\/span>req<span class=\"token punctuation\">,<\/span> res<span class=\"token punctuation\">,<\/span> next<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token function\">next<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><\/code><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td>Path Pattern<\/td>\n<td>\n<pre class=\"language-javascript\"><code class=\"language-javascript\" style=\"color: inherit;\">\/\/ will match paths starting with \/abcd and \/abd\r\napp<span class=\"token punctuation\">.<\/span><span class=\"token function\">use<span class=\"token punctuation\">(<\/span><\/span><span class=\"token string\">'\/abc?d'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token punctuation\">(<\/span>req<span class=\"token punctuation\">,<\/span> res<span class=\"token punctuation\">,<\/span> next<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token function\">next<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n\/\/ will match paths starting with \/abcd, \/abbcd, \/abbbbbcd and so on\r\napp<span class=\"token punctuation\">.<\/span><span class=\"token function\">use<span class=\"token punctuation\">(<\/span><\/span><span class=\"token string\">'\/ab+cd'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token punctuation\">(<\/span>req<span class=\"token punctuation\">,<\/span> res<span class=\"token punctuation\">,<\/span> next<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token function\">next<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n\/\/ will match paths starting with \/abcd, \/abxcd, \/abFOOcd, \/abbArcd and so on\r\napp<span class=\"token punctuation\">.<\/span><span class=\"token function\">use<span class=\"token punctuation\">(<\/span><\/span><span class=\"token string\">'\/ab\\*cd'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token punctuation\">(<\/span>req<span class=\"token punctuation\">,<\/span> res<span class=\"token punctuation\">,<\/span> next<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token function\">next<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n\/\/ will match paths starting with \/ad and \/abcd\r\napp<span class=\"token punctuation\">.<\/span><span class=\"token function\">use<span class=\"token punctuation\">(<\/span><\/span><span class=\"token string\">'\/a(bc)?d'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token punctuation\">(<\/span>req<span class=\"token punctuation\">,<\/span> res<span class=\"token punctuation\">,<\/span> next<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token function\">next<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><\/code><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td>Regular Expression<\/td>\n<td>\n<pre class=\"language-javascript\"><code class=\"language-javascript\" style=\"color: inherit;\">\/\/ will match paths starting with \/abc and \/xyz\r\napp<span class=\"token punctuation\">.<\/span><span class=\"token function\">use<span class=\"token punctuation\">(<\/span><\/span><span class=\"token regex\">\/\\\/abc|\\\/xyz\/<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token punctuation\">(<\/span>req<span class=\"token punctuation\">,<\/span> res<span class=\"token punctuation\">,<\/span> next<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token function\">next<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><\/code><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td>Array<\/td>\n<td>\n<pre class=\"language-javascript\"><code class=\"language-javascript\" style=\"color: inherit;\">\/\/ will match paths starting with \/abcd, \/xyza, \/lmn, and \/pqr\r\napp<span class=\"token punctuation\">.<\/span><span class=\"token function\">use<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">'\/abcd'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">'\/xyza'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">\/<\/span>\\<span class=\"token operator\">\/<\/span>lmn<span class=\"token operator\">|<\/span>\\<span class=\"token operator\">\/<\/span>pqr<span class=\"token operator\">\/<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token punctuation\">(<\/span>req<span class=\"token punctuation\">,<\/span> res<span class=\"token punctuation\">,<\/span> next<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token function\">next<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><\/code><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"kx23\">\u65b9\u6cd5\u53ef\u4ee5\u662f\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u65b9\u6cd5\uff0c\u4e00\u7cfb\u5217\u4e2d\u95f4\u4ef6\u65b9\u6cd5\uff0c\u4e00\u7ec4\u4e2d\u95f4\u4ef6\u65b9\u6cd5\u6216\u8005\u4ed6\u4eec\u7684\u96c6\u5408\u3002\u7531\u4e8e<code style=\"color: #2c3e50;\">router<\/code>\u548c<code style=\"color: #2c3e50;\">app<\/code>\u5b9e\u73b0\u4e86\u4e2d\u95f4\u4ef6\u63a5\u53e3\uff0c\u4f60\u53ef\u4ee5\u50cf\u4f7f\u7528\u5176\u4ed6\u4efb\u4e00\u4e2d\u95f4\u4ef6\u65b9\u6cd5\u90a3\u6837\u4f7f\u7528\u5b83\u4eec\u3002<\/p>\n<table class=\"table table-striped-white table-bordered\" style=\"color: #2c3e50;\" data-anchor-id=\"ao1m\">\n<thead>\n<tr>\n<th style=\"font-weight: bold;\">Usage<\/th>\n<th style=\"font-weight: bold;\">Example<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u5355\u4e2a\u4e2d\u95f4\u4ef6<\/td>\n<td>\u4f60\u53ef\u4ee5\u5c40\u90e8\u5b9a\u4e49\u548c\u6302\u8f7d\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u3002<\/p>\n<pre class=\"language-javascript\"><code class=\"language-javascript\" style=\"color: inherit;\">app<span class=\"token punctuation\">.<\/span><span class=\"token function\">use<span class=\"token punctuation\">(<\/span><\/span><span class=\"token keyword\">function<\/span> <span class=\"token punctuation\">(<\/span>req<span class=\"token punctuation\">,<\/span> res<span class=\"token punctuation\">,<\/span> next<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token function\">next<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span>\r\n<\/code><\/pre>\n<p>\u4e00\u4e2a<code style=\"color: #2c3e50;\">router<\/code>\u662f\u6709\u6548\u7684\u4e2d\u95f4\u4ef6\u3002<\/p>\n<pre class=\"language-javascript\"><code class=\"language-javascript\" style=\"color: inherit;\"><span class=\"token keyword\">var<\/span> router <span class=\"token operator\">=<\/span> express<span class=\"token punctuation\">.<\/span><span class=\"token function\">Router<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\nrouter<span class=\"token punctuation\">.<\/span><span class=\"token keyword\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'\/'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token punctuation\">(<\/span>req<span class=\"token punctuation\">,<\/span> res<span class=\"token punctuation\">,<\/span> next<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token function\">next<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span>\r\napp<span class=\"token punctuation\">.<\/span><span class=\"token function\">use<span class=\"token punctuation\">(<\/span><\/span>router<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<\/code><\/pre>\n<p>\u4e00\u4e2a<code style=\"color: #2c3e50;\">Express<\/code>\u7a0b\u5e8f\u662f\u4e00\u4e2a\u6709\u6548\u7684\u4e2d\u95f4\u4ef6\u3002<\/p>\n<pre class=\"language-javascript\"><code class=\"language-javascript\" style=\"color: inherit;\"><span class=\"token keyword\">var<\/span> subApp <span class=\"token operator\">=<\/span> <span class=\"token function\">express<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\nsubApp<span class=\"token punctuation\">.<\/span><span class=\"token keyword\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'\/'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token punctuation\">(<\/span>req<span class=\"token punctuation\">,<\/span> res<span class=\"token punctuation\">,<\/span> next<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token function\">next<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span>\r\napp<span class=\"token punctuation\">.<\/span><span class=\"token function\">use<span class=\"token punctuation\">(<\/span><\/span>subApp<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<\/code><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td>\u4e00\u7cfb\u5217\u4e2d\u95f4\u4ef6<\/td>\n<td>\u5bf9\u4e8e\u4e00\u4e2a\u76f8\u540c\u7684\u6302\u8f7d\u8def\u5f84\uff0c\u4f60\u53ef\u4ee5\u6302\u8f7d\u8d85\u8fc7\u4e00\u4e2a\u7684\u4e2d\u95f4\u4ef6\u3002<\/p>\n<pre class=\"language-javascript\"><code class=\"language-javascript\" style=\"color: inherit;\"><span class=\"token keyword\">var<\/span> r1 <span class=\"token operator\">=<\/span> express<span class=\"token punctuation\">.<\/span><span class=\"token function\">Router<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\nr1<span class=\"token punctuation\">.<\/span><span class=\"token keyword\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'\/'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token punctuation\">(<\/span>req<span class=\"token punctuation\">,<\/span> res<span class=\"token punctuation\">,<\/span> next<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token function\">next<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n<span class=\"token keyword\">var<\/span> r2 <span class=\"token operator\">=<\/span> express<span class=\"token punctuation\">.<\/span><span class=\"token function\">Router<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\nr2<span class=\"token punctuation\">.<\/span><span class=\"token keyword\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'\/'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token punctuation\">(<\/span>req<span class=\"token punctuation\">,<\/span> res<span class=\"token punctuation\">,<\/span> next<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token function\">next<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\napp<span class=\"token punctuation\">.<\/span><span class=\"token function\">use<span class=\"token punctuation\">(<\/span><\/span>r1<span class=\"token punctuation\">,<\/span> r2<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<\/code><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td>\u4e00\u7ec4\u4e2d\u95f4\u4ef6<\/td>\n<td>\u5728\u903b\u8f91\u4e0a\u4f7f\u7528\u4e00\u4e2a\u6570\u7ec4\u6765\u7ec4\u7ec7\u4e00\u7ec4\u4e2d\u95f4\u4ef6\u3002\u5982\u679c\u4f60\u4f20\u9012\u4e00\u7ec4\u4e2d\u95f4\u4ef6\u4f5c\u4e3a\u7b2c\u4e00\u4e2a\u6216\u8005\u552f\u4e00\u7684\u53c2\u6570\uff0c\u63a5\u7740\u4f60\u9700\u8981\u6307\u5b9a\u6302\u8f7d\u7684\u8def\u5f84\u3002<\/p>\n<pre class=\"language-javascript\"><code class=\"language-javascript\" style=\"color: inherit;\"><span class=\"token keyword\">var<\/span> r1 <span class=\"token operator\">=<\/span> express<span class=\"token punctuation\">.<\/span><span class=\"token function\">Router<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\nr1<span class=\"token punctuation\">.<\/span><span class=\"token keyword\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'\/'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token punctuation\">(<\/span>req<span class=\"token punctuation\">,<\/span> res<span class=\"token punctuation\">,<\/span> next<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token function\">next<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n<span class=\"token keyword\">var<\/span> r2 <span class=\"token operator\">=<\/span> express<span class=\"token punctuation\">.<\/span><span class=\"token function\">Router<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\nr2<span class=\"token punctuation\">.<\/span><span class=\"token keyword\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'\/'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token punctuation\">(<\/span>req<span class=\"token punctuation\">,<\/span> res<span class=\"token punctuation\">,<\/span> next<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token function\">next<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\napp<span class=\"token punctuation\">.<\/span><span class=\"token function\">use<span class=\"token punctuation\">(<\/span><\/span><span class=\"token string\">'\/'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">[<\/span>r1<span class=\"token punctuation\">,<\/span> r2<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<\/code><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td>\u7ec4\u5408<\/td>\n<td>\u4f60\u53ef\u4ee5\u7ec4\u5408\u4e0b\u9762\u7684\u6240\u6709\u65b9\u6cd5\u6765\u6302\u8f7d\u4e2d\u95f4\u4ef6\u3002<\/p>\n<pre class=\"language-javascript\"><code class=\"language-javascript\" style=\"color: inherit;\"><span class=\"token keyword\">function<\/span> <span class=\"token function\">mw1<span class=\"token punctuation\">(<\/span><\/span>req<span class=\"token punctuation\">,<\/span> res<span class=\"token punctuation\">,<\/span> next<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token function\">next<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span>\r\n<span class=\"token keyword\">function<\/span> <span class=\"token function\">mw2<span class=\"token punctuation\">(<\/span><\/span>req<span class=\"token punctuation\">,<\/span> res<span class=\"token punctuation\">,<\/span> next<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token function\">next<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span>\r\n\r\n<span class=\"token keyword\">var<\/span> r1 <span class=\"token operator\">=<\/span> express<span class=\"token punctuation\">.<\/span><span class=\"token function\">Router<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\nr1<span class=\"token punctuation\">.<\/span><span class=\"token keyword\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'\/'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token punctuation\">(<\/span>req<span class=\"token punctuation\">,<\/span> res<span class=\"token punctuation\">,<\/span> next<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token function\">next<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n\r\n<span class=\"token keyword\">var<\/span> r2 <span class=\"token operator\">=<\/span> express<span class=\"token punctuation\">.<\/span><span class=\"token function\">Router<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\nr2<span class=\"token punctuation\">.<\/span><span class=\"token keyword\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'\/'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token punctuation\">(<\/span>req<span class=\"token punctuation\">,<\/span> res<span class=\"token punctuation\">,<\/span> next<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token function\">next<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n\r\n<span class=\"token keyword\">var<\/span> subApp <span class=\"token operator\">=<\/span> <span class=\"token function\">express<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\nsubApp<span class=\"token punctuation\">.<\/span><span class=\"token keyword\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'\/'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token punctuation\">(<\/span>req<span class=\"token punctuation\">,<\/span> res<span class=\"token punctuation\">,<\/span> next<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token function\">next<span class=\"token punctuation\">(<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n\r\napp<span class=\"token punctuation\">.<\/span><span class=\"token function\">use<span class=\"token punctuation\">(<\/span><\/span>mw1<span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">[<\/span>mw2<span class=\"token punctuation\">,<\/span> r1<span class=\"token punctuation\">,<\/span> r2<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> subApp<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<\/code><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"07tm\">\u4e0b\u9762\u662f\u4e00\u4e9b\u4f8b\u5b50\uff0c\u5728<code style=\"color: #2c3e50;\">Express<\/code>\u7a0b\u5e8f\u4e2d\u4f7f\u7528<code style=\"color: #2c3e50;\">express.static<\/code>\u4e2d\u95f4\u4ef6\u3002<br \/>\n\u4e3a\u7a0b\u5e8f\u6258\u7ba1\u4f4d\u4e8e\u7a0b\u5e8f\u76ee\u5f55\u4e0b\u7684<code style=\"color: #2c3e50;\">public<\/code>\u76ee\u5f55\u4e0b\u7684\u9759\u6001\u8d44\u6e90\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ GET \/style.css etc<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">express<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">static<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">__dirname <\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"str\" style=\"color: #008800;\">'\/public'<\/span><span class=\"pun\" style=\"color: #666600;\">));<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"v16n\">\u5728<code style=\"color: #2c3e50;\">\/static<\/code>\u8def\u5f84\u4e0b\u6302\u8f7d\u4e2d\u95f4\u4ef6\u6765\u63d0\u4f9b\u9759\u6001\u8d44\u6e90\u6258\u7ba1\u670d\u52a1\uff0c\u53ea\u5f53\u8bf7\u6c42\u662f\u4ee5<code style=\"color: #2c3e50;\">\/static<\/code>\u4e3a\u524d\u7f00\u7684\u65f6\u5019\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ GET \/static\/style.css etc.<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/static'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> express<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">static<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">express<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">__dirname <\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"str\" style=\"color: #008800;\">'\/public'<\/span><span class=\"pun\" style=\"color: #666600;\">));<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"5hl5\">\u901a\u8fc7\u5728\u8bbe\u7f6e\u9759\u6001\u8d44\u6e90\u4e2d\u95f4\u4ef6\u4e4b\u540e\u52a0\u8f7d\u65e5\u5fd7\u4e2d\u95f4\u4ef6\u6765\u5173\u95ed\u9759\u6001\u8d44\u6e90\u8bf7\u6c42\u7684\u65e5\u5fd7\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">express<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">static<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">__dirname <\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"str\" style=\"color: #008800;\">'\/public'<\/span><span class=\"pun\" style=\"color: #666600;\">));<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">logger<\/span><span class=\"pun\" style=\"color: #666600;\">());<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"2kqe\">\u6258\u7ba1\u9759\u6001\u8d44\u6e90\u4ece\u4e0d\u540c\u7684\u8def\u5f84\uff0c\u4f46<code style=\"color: #2c3e50;\">.\/public<\/code>\u8def\u5f84\u6bd4\u5176\u4ed6\u66f4\u5bb9\u6613\u88ab\u5339\u914d\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">express<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">static<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">__dirname <\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"str\" style=\"color: #008800;\">'\/public'<\/span><span class=\"pun\" style=\"color: #666600;\">));<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">express<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">static<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">__dirname <\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"str\" style=\"color: #008800;\">'\/files'<\/span><span class=\"pun\" style=\"color: #666600;\">));<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">express<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">static<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">__dirname <\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"str\" style=\"color: #008800;\">'\/uploads'<\/span><span class=\"pun\" style=\"color: #666600;\">));<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h2 id=\"request\" style=\"color: #2c3e50;\" data-anchor-id=\"xkuq\">Request<\/h2>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"43lp\"><code style=\"color: #2c3e50;\">req<\/code>\u5bf9\u8c61\u4ee3\u8868\u4e86\u4e00\u4e2aHTTP\u8bf7\u6c42\uff0c\u5176\u5177\u6709\u4e00\u4e9b\u5c5e\u6027\u6765\u4fdd\u5b58\u8bf7\u6c42\u4e2d\u7684\u4e00\u4e9b\u6570\u636e\uff0c\u6bd4\u5982<code style=\"color: #2c3e50;\">query string<\/code>\uff0c<code style=\"color: #2c3e50;\">parameters<\/code>\uff0c<code style=\"color: #2c3e50;\">body<\/code>\uff0c<code style=\"color: #2c3e50;\">HTTP headers<\/code>\u7b49\u7b49\u3002\u5728\u672c\u6587\u6863\u4e2d\uff0c\u6309\u7167\u60ef\u4f8b\uff0c\u8fd9\u4e2a\u5bf9\u8c61\u603b\u662f\u7b80\u79f0\u4e3a<code style=\"color: #2c3e50;\">req<\/code>(http\u54cd\u5e94\u7b80\u79f0\u4e3a<code style=\"color: #2c3e50;\">res<\/code>)\uff0c\u4f46\u662f\u5b83\u4eec\u5b9e\u9645\u7684\u540d\u5b57\u7531\u8fd9\u4e2a\u56de\u8c03\u65b9\u6cd5\u5728\u90a3\u91cc\u4f7f\u7528\u65f6\u7684\u53c2\u6570\u51b3\u5b9a\u3002<br \/>\n\u5982\u4e0b\u4f8b\u5b50:<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/user\/:id'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'user'<\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"pln\" style=\"color: #000000;\"> req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">params<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">id<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"vjww\">\u5176\u5b9e\u4f60\u4e5f\u53ef\u4ee5\u8fd9\u6837\u5199\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/user\/:id'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">request<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> response<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> response<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'user'<\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"pln\" style=\"color: #000000;\"> request<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">params<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">id<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h3 id=\"properties-1\" style=\"color: #2c3e50;\" data-anchor-id=\"gutb\">Properties<\/h3>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"a5y2\">\u5728<code style=\"color: #2c3e50;\">Express 4<\/code>\u4e2d\uff0c<code style=\"color: #2c3e50;\">req.files<\/code>\u9ed8\u8ba4\u5728<code style=\"color: #2c3e50;\">req<\/code>\u5bf9\u8c61\u4e2d\u4e0d\u518d\u662f\u53ef\u7528\u7684\u3002\u4e3a\u4e86\u901a\u8fc7<code style=\"color: #2c3e50;\">req.files<\/code>\u5bf9\u8c61\u6765\u83b7\u5f97\u4e0a\u4f20\u7684\u6587\u4ef6\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a<code style=\"color: #2c3e50;\">multipart-handling<\/code>(\u591a\u79cd\u5904\u7406\u7684\u5de5\u5177\u96c6)\u4e2d\u95f4\u4ef6\uff0c\u6bd4\u5982<code style=\"color: #2c3e50;\">busboy<\/code>\uff0c<code style=\"color: #2c3e50;\">multer<\/code>\uff0c<code style=\"color: #2c3e50;\">formidable<\/code>\uff0c<code style=\"color: #2c3e50;\">multipraty<\/code>\uff0c<code style=\"color: #2c3e50;\">connect-multiparty<\/code>\u6216\u8005<code style=\"color: #2c3e50;\">pez<\/code>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqapp\" style=\"color: #2c3e50;\" data-anchor-id=\"evix\">req.app<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"b9ng\">\u8fd9\u4e2a\u5c5e\u6027\u6301\u6709<code style=\"color: #2c3e50;\">express<\/code>\u7a0b\u5e8f\u5b9e\u4f8b\u7684\u4e00\u4e2a\u5f15\u7528\uff0c\u5176\u53ef\u4ee5\u4f5c\u4e3a\u4e2d\u95f4\u4ef6\u4f7f\u7528\u3002<br \/>\n\u5982\u679c\u4f60\u6309\u7167\u8fd9\u4e2a\u6a21\u5f0f\uff0c\u4f60\u521b\u5efa\u4e00\u4e2a\u6a21\u5757\u5bfc\u51fa\u4e00\u4e2a\u4e2d\u95f4\u4ef6\uff0c\u8fd9\u4e2a\u4e2d\u95f4\u4ef6\u53ea\u5728\u4f60\u7684\u4e3b\u6587\u4ef6\u4e2d<code style=\"color: #2c3e50;\">require()<\/code>\u5b83\uff0c\u90a3\u4e48\u8fd9\u4e2a\u4e2d\u95f4\u4ef6\u53ef\u4ee5\u901a\u8fc7<code style=\"color: #2c3e50;\">req.app<\/code>\u6765\u83b7\u53d6express\u7684\u5b9e\u4f8b\u3002<br \/>\n\u4f8b\u5982:<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ index.js<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">\"\/viewdirectory\"<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> require<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'.\/mymiddleware.js'<\/span><span class=\"pun\" style=\"color: #666600;\">));<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ mymiddleware.js<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">module<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">exports <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'The views directory is '<\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"pln\" style=\"color: #000000;\"> req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'views'<\/span><span class=\"pun\" style=\"color: #666600;\">));<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">};<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqbaseurl\" style=\"color: #2c3e50;\" data-anchor-id=\"iw2s\">req.baseUrl<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"kvqw\">\u4e00\u4e2a\u8def\u7531\u5b9e\u4f8b\u6302\u8f7d\u7684Url\u8def\u5f84\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> greet <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> express<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"typ\" style=\"color: #660066;\">Router<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> greet<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/jp'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">baseUrl<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ greet<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Konichiwa!'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/greet'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> greet<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"lvwm\">\u5373\u4f7f\u4f60\u4f7f\u7528\u7684\u8def\u5f84\u6a21\u5f0f\u6216\u8005\u4e00\u7cfb\u5217\u8def\u5f84\u6a21\u5f0f\u6765\u52a0\u8f7d\u8def\u7531\uff0c<code style=\"color: #2c3e50;\">baseUrl<\/code>\u5c5e\u6027\u8fd4\u56de\u5339\u914d\u7684\u5b57\u7b26\u4e32\uff0c\u800c\u4e0d\u662f\u8def\u7531\u6a21\u5f0f\u3002\u4e0b\u9762\u7684\u4f8b\u5b50\uff0c<code style=\"color: #2c3e50;\">greet<\/code>\u8def\u7531\u88ab\u52a0\u8f7d\u5728\u4e24\u4e2a\u8def\u5f84\u6a21\u5f0f\u4e0a\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">([<\/span><span class=\"str\" style=\"color: #008800;\">'\/gre+t'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'hel{2}o'<\/span><span class=\"pun\" style=\"color: #666600;\">],<\/span><span class=\"pln\" style=\"color: #000000;\"> greet<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ load the on router on '\/gre+t' and '\/hel{2}o'<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"2kxn\">\u5f53\u4e00\u4e2a\u8bf7\u6c42\u8def\u5f84\u662f<code style=\"color: #2c3e50;\">\/greet\/jp<\/code>\uff0c<code style=\"color: #2c3e50;\">baseUrl<\/code>\u662f<code style=\"color: #2c3e50;\">\/greet<\/code>\uff0c\u5f53\u4e00\u4e2a\u8bf7\u6c42\u8def\u5f84\u662f<code style=\"color: #2c3e50;\">\/hello\/jp<\/code>\uff0c<code style=\"color: #2c3e50;\">req.baseUrl<\/code>\u662f<code style=\"color: #2c3e50;\">\/hello<\/code>\u3002<br \/>\n<code style=\"color: #2c3e50;\">req.baseUrl<\/code>\u548c<code style=\"color: #2c3e50;\">app<\/code>\u5bf9\u8c61\u7684<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#app.mountpath\" target=\"_blank\">mountpath<\/a>\u5c5e\u6027\u76f8\u4f3c\uff0c\u9664\u4e86<code style=\"color: #2c3e50;\">app.mountpath<\/code>\u8fd4\u56de\u7684\u662f\u8def\u5f84\u5339\u914d\u6a21\u5f0f\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqbody\" style=\"color: #2c3e50;\" data-anchor-id=\"p24l\">req.body<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"7ubs\">\u5728\u8bf7\u6c42\u7684body\u4e2d\u4fdd\u5b58\u7684\u662f\u63d0\u4ea4\u7684\u4e00\u5bf9\u5bf9\u952e\u503c\u6570\u636e\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5b83\u662f<code style=\"color: #2c3e50;\">undefined<\/code>\uff0c\u5f53\u4f60\u4f7f\u7528\u6bd4\u5982<code style=\"color: #2c3e50;\">body-parser<\/code>\u548c<code style=\"color: #2c3e50;\">multer<\/code>\u8fd9\u7c7b\u89e3\u6790<code style=\"color: #2c3e50;\">body<\/code>\u6570\u636e\u7684\u4e2d\u95f4\u4ef6\u65f6\uff0c\u5b83\u662f\u586b\u5145\u7684\u3002<br \/>\n\u4e0b\u9762\u7684\u4f8b\u5b50\uff0c\u7ed9\u4f60\u5c55\u793a\u4e86\u600e\u4e48\u4f7f\u7528<code style=\"color: #2c3e50;\">body-parser<\/code>\u4e2d\u95f4\u4ef6\u6765\u586b\u5145<code style=\"color: #2c3e50;\">req.body<\/code>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> app <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> require<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'express'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> bodyParser <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> require<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'body-parser'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> multer <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> require<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'multer'<\/span><span class=\"pun\" style=\"color: #666600;\">)\uff1b<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ v1.0.5<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> upload <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> multer<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ for parsing multipart\/form-data<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">bodyParser<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">json<\/span><span class=\"pun\" style=\"color: #666600;\">());<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ for parsing application\/json<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">bodyParser<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">urlencoded<\/span><span class=\"pun\" style=\"color: #666600;\">({<\/span><span class=\"pln\" style=\"color: #000000;\">extended<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"kwd\" style=\"color: #000088;\">true<\/span><span class=\"pun\" style=\"color: #666600;\">}));<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ for parsing application\/x-www-form-urlencoded<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">post<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/profile'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> upload<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">array<\/span><span class=\"pun\" style=\"color: #666600;\">(),<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">body<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">json<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">body<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqcookies\" style=\"color: #2c3e50;\" data-anchor-id=\"e4y7\">req.cookies<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"pguk\">\u5f53\u4f7f\u7528<code style=\"color: #2c3e50;\">cookie-parser<\/code>\u4e2d\u95f4\u4ef6\u7684\u65f6\u5019\uff0c\u8fd9\u4e2a\u5c5e\u6027\u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5176\u5305\u542b\u4e86\u8bf7\u6c42\u53d1\u9001\u8fc7\u6765\u7684<code style=\"color: #2c3e50;\">cookies<\/code>\u3002\u5982\u679c\u8bf7\u6c42\u6ca1\u6709\u5e26<code style=\"color: #2c3e50;\">cookies<\/code>\uff0c\u90a3\u4e48\u5176\u503c\u4e3a<code style=\"color: #2c3e50;\">{}<\/code>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ Cookie: name=tj<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">cookies<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">name<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"tj\"<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"g6u5\">\u83b7\u53d6\u66f4\u591a\u4fe1\u606f\uff0c\u95ee\u9898\uff0c\u6216\u8005\u5173\u6ce8\uff0c\u53ef\u4ee5\u67e5\u9605<a style=\"color: #0088cc;\" href=\"https:\/\/github.com\/expressjs\/cookie-parser?_ga=1.268562033.1201680737.1446005628\" target=\"_blank\">cookie-parser<\/a>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqfresh\" style=\"color: #2c3e50;\" data-anchor-id=\"iqqk\">req.fresh<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"mwgm\">\u6307\u793a\u8fd9\u4e2a\u8bf7\u6c42\u662f\u5426\u662f\u65b0\u9c9c\u7684\u3002\u5176\u548c<code style=\"color: #2c3e50;\">req.stale<\/code>\u662f\u76f8\u53cd\u7684\u3002<br \/>\n\u5f53<code style=\"color: #2c3e50;\">cache-control<\/code>\u8bf7\u6c42\u5934\u6ca1\u6709<code style=\"color: #2c3e50;\">no-cache<\/code>\u6307\u793a\u548c\u4e0b\u9762\u4e2d\u7684\u4efb\u4e00\u4e00\u4e2a\u6761\u4ef6\u4e3a<code style=\"color: #2c3e50;\">true<\/code>\uff0c\u90a3\u4e48\u5176\u5c31\u4e3a<code style=\"color: #2c3e50;\">true<\/code>\uff1a<\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li style=\"color: #2c3e50;\" data-anchor-id=\"sdi6\"><code style=\"color: #2c3e50;\">if-modified-since<\/code>\u8bf7\u6c42\u5934\u88ab\u6307\u5b9a\uff0c\u548c<code style=\"color: #2c3e50;\">last-modified<\/code>\u8bf7\u6c42\u5934\u7b49\u4e8e\u6216\u8005\u65e9\u4e8e<code style=\"color: #2c3e50;\">modified<\/code>\u54cd\u5e94\u5934\u3002<\/li>\n<li style=\"color: #2c3e50;\" data-anchor-id=\"oi70\"><code style=\"color: #2c3e50;\">if-none-match<\/code>\u8bf7\u6c42\u5934\u662f<code style=\"color: #2c3e50;\">*<\/code>\u3002<\/li>\n<li style=\"color: #2c3e50;\" data-anchor-id=\"m9c5\"><code style=\"color: #2c3e50;\">if-none-match<\/code>\u8bf7\u6c42\u5934\u5728\u88ab\u89e3\u6790\u8fdb\u5b83\u7684\u6307\u4ee4\u4e4b\u540e\uff0c\u4e0d\u5339\u914d<code style=\"color: #2c3e50;\">etag<\/code>\u54cd\u5e94\u5934(\u5b8c\u5168\u4e0d\u77e5\u9053\u4ec0\u4e48\u9b3c)\u3002<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">fresh<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; true<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqhostname\" style=\"color: #2c3e50;\" data-anchor-id=\"th1s\">req.hostname<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"a67l\">\u5305\u542b\u4e86\u6e90\u81ea<code style=\"color: #2c3e50;\">Host<\/code>HTTP\u5934\u90e8\u7684<code style=\"color: #2c3e50;\">hostname<\/code>\u3002<br \/>\n\u5f53<code style=\"color: #2c3e50;\">trust proxy<\/code>\u8bbe\u7f6e\u9879\u88ab\u8bbe\u7f6e\u4e3a\u542f\u7528\u503c\uff0c<code style=\"color: #2c3e50;\">X-Forwarded-Host<\/code>\u5934\u90e8\u88ab\u4f7f\u7528\u6765\u4ee3\u66ff<code style=\"color: #2c3e50;\">Host<\/code>\u3002\u8fd9\u4e2a\u5934\u90e8\u53ef\u4ee5\u88ab\u5ba2\u6237\u7aef\u6216\u8005\u4ee3\u7406\u8bbe\u7f6e\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ Host: \"example.com\"<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">hostname<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"example.com\"<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqips\" style=\"color: #2c3e50;\" data-anchor-id=\"1llv\">req.ips<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"kica\">\u5f53<code style=\"color: #2c3e50;\">trust proxy<\/code>\u8bbe\u7f6e\u9879\u88ab\u8bbe\u7f6e\u4e3a\u542f\u7528\u503c\uff0c\u8fd9\u4e2a\u5c5e\u6027\u5305\u542b\u4e86\u4e00\u7ec4\u5728<code style=\"color: #2c3e50;\">X-Forwarded-For<\/code>\u8bf7\u6c42\u5934\u4e2d\u6307\u5b9a\u7684IP\u5730\u5740\u3002\u4e0d\u7136\uff0c\u5176\u5c31\u5305\u542b\u4e00\u4e2a\u7a7a\u7684\u6570\u7ec4\u3002\u8fd9\u4e2a\u5934\u90e8\u53ef\u4ee5\u88ab\u5ba2\u6237\u7aef\u6216\u8005\u4ee3\u7406\u8bbe\u7f6e\u3002<br \/>\n\u4f8b\u5982\uff0c\u5982\u679c<code style=\"color: #2c3e50;\">X-Forwarded-For<\/code>\u662f<code style=\"color: #2c3e50;\">client<\/code>\uff0c<code style=\"color: #2c3e50;\">proxy1<\/code>\uff0c<code style=\"color: #2c3e50;\">proxy2<\/code>\uff0c<code style=\"color: #2c3e50;\">req.ips<\/code>\u5c31\u662f<code style=\"color: #2c3e50;\">[\"clinet\", \"proxy1\", \"proxy2\"]<\/code>\uff0c\u8fd9\u91cc<code style=\"color: #2c3e50;\">proxy2<\/code>\u5c31\u662f\u6700\u8fdc\u7684\u4e0b\u6e38\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqoriginalurl\" style=\"color: #2c3e50;\" data-anchor-id=\"x7z3\">req.originalUrl<\/h4>\n<blockquote class=\"white-blockquote\" style=\"color: #2c3e50;\" data-anchor-id=\"ocfi\">\n<p style=\"font-weight: 300;\"><code style=\"color: #2c3e50;\">req.url<\/code>\u4e0d\u662f\u4e00\u4e2a\u539f\u751f\u7684<code style=\"color: #2c3e50;\">Express<\/code>\u5c5e\u6027\uff0c\u5b83\u7ee7\u627f\u81ea<a style=\"color: #0088cc;\" href=\"https:\/\/nodejs.org\/api\/http.html#http_message_url\" target=\"_blank\">Node&#8217;s http module<\/a>\u3002<\/p>\n<\/blockquote>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"zrfo\">\u8fd9\u4e2a\u5c5e\u6027\u5f88\u50cf<code style=\"color: #2c3e50;\">req.url<\/code>\uff1b\u7136\u800c\uff0c\u5176\u4fdd\u7559\u4e86\u539f\u7248\u7684\u8bf7\u6c42\u94fe\u63a5\uff0c\u5141\u8bb8\u4f60\u81ea\u7531\u5730\u91cd\u5b9a\u5411<code style=\"color: #2c3e50;\">req.url<\/code>\u5230\u5185\u90e8\u8def\u7531\u3002\u6bd4\u5982\uff0c<code style=\"color: #2c3e50;\">app.use()<\/code>\u7684<code style=\"color: #2c3e50;\">mounting<\/code>\u7279\u70b9\u53ef\u4ee5\u91cd\u5b9a\u5411<code style=\"color: #2c3e50;\">req.url<\/code>\u8df3\u8f6c\u5230\u6302\u8f7d\u70b9\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ GET \/search?q=something<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">originalUrl<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"\/search?q=something\"<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqparams\" style=\"color: #2c3e50;\" data-anchor-id=\"8uli\">req.params<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"v3tc\">\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5176\u5305\u542b\u4e86\u4e00\u7cfb\u5217\u7684\u5c5e\u6027\uff0c\u8fd9\u4e9b\u5c5e\u6027\u548c\u5728\u8def\u7531\u4e2d\u547d\u540d\u7684\u53c2\u6570\u540d\u662f\u4e00\u4e00\u5bf9\u5e94\u7684\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u6709<code style=\"color: #2c3e50;\">\/user\/:name<\/code>\u8def\u7531\uff0c<code style=\"color: #2c3e50;\">name<\/code>\u5c5e\u6027\u53ef\u4f5c\u4e3a<code style=\"color: #2c3e50;\">req.params.name<\/code>\u3002\u8fd9\u4e2a\u5bf9\u8c61\u9ed8\u8ba4\u503c\u4e3a<code style=\"color: #2c3e50;\">{}<\/code>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ GET \/user\/tj<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">params<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">name<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"tj\"<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"k948\">\u5f53\u4f60\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u5b9a\u4e49\u8def\u7531\u89c4\u5219\uff0c\u6355\u83b7\u7ec4\u7684\u7ec4\u5408\u4e00\u822c\u4f7f\u7528<code style=\"color: #2c3e50;\">req.params[n]<\/code>\uff0c\u8fd9\u91cc\u7684<code style=\"color: #2c3e50;\">n<\/code>\u662f\u7b2c\u51e0\u4e2a\u6355\u83b7\u79df\u3002\u8fd9\u4e2a\u89c4\u5219\u88ab\u65bd\u52a0\u5728\u65e0\u540d\u901a\u914d\u7b26\u5339\u914d\uff0c\u6bd4\u5982<code style=\"color: #2c3e50;\">\/file\/*<\/code>\u7684\u8def\u7531\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ GET \/file\/javascripts\/jquery.js<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">params<\/span><span class=\"pun\" style=\"color: #666600;\">[<\/span><span class=\"lit\" style=\"color: #006666;\">0<\/span><span class=\"pun\" style=\"color: #666600;\">]<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"javascripts\/jquery.js\"<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqpath\" style=\"color: #2c3e50;\" data-anchor-id=\"fnd1\">req.path<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"nnqd\">\u5305\u542b\u8bf7\u6c42URL\u7684\u90e8\u5206\u8def\u5f84\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ example.com\/users?sort=desc<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">path<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"\/users\"<\/span><\/code><\/li>\n<\/ol>\n<blockquote class=\"white-blockquote\" style=\"color: #2c3e50;\" data-anchor-id=\"ye8j\">\n<p style=\"font-weight: 300;\">\u5f53\u5728\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u4e2d\u88ab\u8c03\u7528\uff0c\u6302\u8f7d\u70b9\u4e0d\u5305\u542b\u5728<code style=\"color: #2c3e50;\">req.path<\/code>\u4e2d\u3002\u4f60\u53ef\u4ee5\u67e5\u9605<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#app.use\" target=\"_blank\">app.use()<\/a>\u83b7\u5f97\u8ddf\u591a\u7684\u4fe1\u606f\u3002<\/p>\n<\/blockquote>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqprotocol\" style=\"color: #2c3e50;\" data-anchor-id=\"8zmz\">req.protocol<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"9ybt\">\u8bf7\u6c42\u7684\u534f\u8bae\uff0c\u4e00\u822c\u4e3a<code style=\"color: #2c3e50;\">http<\/code>\uff0c\u5f53\u542f\u7528TLS\u52a0\u5bc6\uff0c\u5219\u4e3a<code style=\"color: #2c3e50;\">https<\/code>\u3002<br \/>\n\u5f53<code style=\"color: #2c3e50;\">trust proxy<\/code>\u8bbe\u7f6e\u4e00\u4e2a\u542f\u7528\u7684\u53c2\u6570\uff0c\u5982\u679c\u5b58\u5728<code style=\"color: #2c3e50;\">X-Forwarded-Proto<\/code>\u5934\u90e8\u7684\u8bdd\uff0c\u5176\u5c06\u88ab\u4fe1\u8d56\u548c\u4f7f\u7528\u3002\u8fd9\u4e2a\u5934\u90e8\u53ef\u4ee5\u88ab\u5ba2\u6237\u7aef\u6216\u8005\u4ee3\u7406\u8bbe\u7f6e\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">ptotocol<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"http\"<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqquery\" style=\"color: #2c3e50;\" data-anchor-id=\"vtxn\">req.query<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"gfqx\">\u4e00\u4e2a\u5bf9\u8c61\uff0c\u4e3a\u6bcf\u4e00\u4e2a\u8def\u7531\u4e2d\u7684<code style=\"color: #2c3e50;\">query string<\/code>\u53c2\u6570\u90fd\u5206\u914d\u4e00\u4e2a\u5c5e\u6027\u3002\u5982\u679c\u6ca1\u6709<code style=\"color: #2c3e50;\">query string<\/code>\uff0c\u5b83\u5c31\u662f\u4e00\u4e2a\u7a7a\u5bf9\u8c61\uff0c<code style=\"color: #2c3e50;\">{}<\/code>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ GET \/search?q=tobi+ferret<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">query<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">q<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"tobi ferret\"<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ GET \/shoes?order=desc&amp;shoe[color]=blue&amp;shoe[type]=converse<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">query<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">order<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"desc\"<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">query<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">shoe<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">color<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"blue\"<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">query<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">shoe<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">type<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"converse\"<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqroute\" style=\"color: #2c3e50;\" data-anchor-id=\"026w\">req.route<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"n2z9\">\u5f53\u524d\u5339\u914d\u7684\u8def\u7531\uff0c\u5176\u4e3a\u4e00\u4e32\u5b57\u7b26\u3002\u6bd4\u5982\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/user\/:id?'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pln\" style=\"color: #000000;\"> userIdHandler<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">route<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'GET'<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">})<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"i7xq\">\u524d\u9762\u7247\u6bb5\u7684\u8f93\u51fa\u4e3a:<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">{<\/span><span class=\"pln\" style=\"color: #000000;\"> path<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">\"\/user\/:id?\"<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> stack<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">[<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">{<\/span><span class=\"pln\" style=\"color: #000000;\"> handle<\/span><span class=\"pun\" style=\"color: #666600;\">:[<\/span><span class=\"typ\" style=\"color: #660066;\">Function<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"pln\" style=\"color: #000000;\">userIdHandler<\/span><span class=\"pun\" style=\"color: #666600;\">],<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> name<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">\"userIdHandler\"<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> params<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"kwd\" style=\"color: #000088;\">undefined<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> path<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"kwd\" style=\"color: #000088;\">undefined<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> keys<\/span><span class=\"pun\" style=\"color: #666600;\">:[],<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> regexp<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">\/^\\\/?$\/<\/span><span class=\"pln\" style=\"color: #000000;\">i<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> method<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'get'<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">]<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> methods<\/span><span class=\"pun\" style=\"color: #666600;\">:{<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"kwd\" style=\"color: #000088;\">true<\/span><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqsecure\" style=\"color: #2c3e50;\" data-anchor-id=\"rf7e\">req.secure<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"pbmj\">\u4e00\u4e2a\u5e03\u5c14\u503c\uff0c\u5982\u679c\u5efa\u7acb\u7684\u662fTLS\u7684\u8fde\u63a5\uff0c\u90a3\u4e48\u5c31\u4e3a<code style=\"color: #2c3e50;\">true<\/code>\u3002\u7b49\u4ef7\u4e0e\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"str\" style=\"color: #008800;\">'https'<\/span><span class=\"pun\" style=\"color: #666600;\">==<\/span><span class=\"pln\" style=\"color: #000000;\"> req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">protocol<\/span><span class=\"pun\" style=\"color: #666600;\">;<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqsignedcookies\" style=\"color: #2c3e50;\" data-anchor-id=\"ti2k\">req.signedCookies<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"63z8\">\u5f53\u4f7f\u7528<code style=\"color: #2c3e50;\">cookie-parser<\/code>\u4e2d\u95f4\u4ef6\u7684\u65f6\u5019\uff0c\u8fd9\u4e2a\u5c5e\u6027\u5305\u542b\u7684\u662f\u8bf7\u6c42\u53d1\u8fc7\u6765\u7684\u7b7e\u540d<code style=\"color: #2c3e50;\">cookies<\/code>\uff0c\u4e0d\u7b7e\u540d\u7684\u5e76\u4e14\u4e3a\u4f7f\u7528\u505a\u597d\u4e86\u51c6\u5907(\u8fd9\u53e5\u771f\u4e0d\u77e5\u9053\u600e\u4e48\u7ffb\u8bd1\u4e86&#8230;)\u3002\u7b7e\u540d<code style=\"color: #2c3e50;\">cookies<\/code>\u9a7b\u7559\u5728\u4e0d\u540c\u7684\u5bf9\u8c61\u4e2d\u6765\u4f53\u73b0\u5f00\u53d1\u8005\u7684\u610f\u56fe\uff1b\u4e0d\u7136\uff0c\u4e00\u4e2a\u6076\u610f\u653b\u51fb\u53ef\u4ee5\u88ab\u65bd\u52a0\u5728<code style=\"color: #2c3e50;\">req.cookie<\/code>\u503c\u4e0a(\u5b83\u662f\u5f88\u5bb9\u6613\u88ab\u6b3a\u9a97\u7684)\u3002\u8bb0\u4f4f\uff0c\u7b7e\u540d\u4e00\u4e2a<code style=\"color: #2c3e50;\">cookie<\/code>\u4e0d\u662f\u628a\u5b83\u85cf\u8d77\u6765\u6216\u8005\u52a0\u5bc6\uff1b\u800c\u662f\u7b80\u5355\u7684\u9632\u6b62\u7be1\u6539(\u56e0\u4e3a\u7b7e\u540d\u4f7f\u7528\u7684\u52a0\u5bc6\u662f\u79c1\u4eba\u7684)\u3002\u5982\u679c\u6ca1\u6709\u53d1\u9001\u7b7e\u540d\u7684<code style=\"color: #2c3e50;\">cookie<\/code>\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5c5e\u6027\u9ed8\u8ba4\u4e3a<code style=\"color: #2c3e50;\">{}<\/code>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ Cookie\uff1a user=tobi.CP7AWaXDfAKIRfH49dQzKJx7sKzzSoPq7\/AcBBRVwlI3<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">signedCookies<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">user<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"tobi\"<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"b8rf\">\u4e3a\u4e86\u83b7\u53d6\u66f4\u591a\u7684\u4fe1\u606f\uff0c\u95ee\u9898\u6216\u8005\u5173\u6ce8\uff0c\u53ef\u4ee5\u53c2\u9605<a style=\"color: #0088cc;\" href=\"https:\/\/github.com\/expressjs\/cookie-parser?_ga=1.25372221.1201680737.1446005628\" target=\"_blank\">cookie-parser<\/a>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqstale\" style=\"color: #2c3e50;\" data-anchor-id=\"uy6i\">req.stale<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"7e18\">\u6307\u793a\u8fd9\u4e2a\u8bf7\u6c42\u662f\u5426\u662f<code style=\"color: #2c3e50;\">stale<\/code>(\u9648\u65e7\u7684)\uff0c\u5b83\u4e0e<code style=\"color: #2c3e50;\">req.fresh<\/code>\u662f\u76f8\u53cd\u7684\u3002\u66f4\u591a\u4fe1\u606f\uff0c\u53ef\u4ee5\u67e5\u770b<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#req.fresh\" target=\"_blank\">req.fresh<\/a>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">stale<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; true<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqsubdomains\" style=\"color: #2c3e50;\" data-anchor-id=\"zylj\">req.subdomains<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"c2tw\">\u8bf7\u6c42\u4e2d\u57df\u540d\u7684\u5b50\u57df\u540d\u6570\u7ec4\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ Host: \"tobi.ferrets.example.com\"<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">subdomains<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; [\"ferrets\", \"tobi\"]<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqxhr\" style=\"color: #2c3e50;\" data-anchor-id=\"ulzp\">req.xhr<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"gryw\">\u4e00\u4e2a\u5e03\u5c14\u503c\uff0c\u5982\u679c<code style=\"color: #2c3e50;\">X-Requested-With<\/code>\u7684\u503c\u4e3a<code style=\"color: #2c3e50;\">XMLHttpRequest<\/code>\uff0c\u90a3\u4e48\u5176\u4e3a<code style=\"color: #2c3e50;\">true<\/code>\uff0c\u5176\u6307\u793a\u8fd9\u4e2a\u8bf7\u6c42\u662f\u88ab\u4e00\u4e2a\u5ba2\u670d\u7aef\u5e93\u53d1\u9001\uff0c\u6bd4\u5982<code style=\"color: #2c3e50;\">jQuery<\/code>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">xhr<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; true<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h3 id=\"methods-2\" style=\"color: #2c3e50;\" data-anchor-id=\"a6bk\">Methods<\/h3>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqacceptstypes\" style=\"color: #2c3e50;\" data-anchor-id=\"jidj\">req.accepts(types)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"2t1c\">\u68c0\u67e5\u8fd9\u4e2a\u6307\u5b9a\u7684\u5185\u5bb9\u7c7b\u578b\u662f\u5426\u88ab\u63a5\u53d7\uff0c\u57fa\u4e8e\u8bf7\u6c42\u7684<code style=\"color: #2c3e50;\">Accept<\/code>\u00a0HTTP\u5934\u90e8\u3002\u8fd9\u4e2a\u65b9\u6cd5\u8fd4\u56de\u6700\u4f73\u5339\u914d\uff0c\u5982\u679c\u6ca1\u6709\u4e00\u4e2a\u5339\u914d\uff0c\u90a3\u4e48\u5176\u8fd4\u56de<code style=\"color: #2c3e50;\">undefined<\/code>(\u5728\u8fd9\u4e2acase\u4e0b\uff0c\u670d\u52a1\u5668\u7aef\u5e94\u8be5\u8fd4\u56de406\u548c&#8221;Not Acceptable&#8221;)\u3002<br \/>\n<code style=\"color: #2c3e50;\">type<\/code>\u503c\u53ef\u4ee5\u662f\u4e00\u4e2a\u5355\u7684<code style=\"color: #2c3e50;\">MIME type<\/code>\u5b57\u7b26\u4e32(\u6bd4\u5982<code style=\"color: #2c3e50;\">application\/json<\/code>)\uff0c\u4e00\u4e2a\u6269\u5c55\u540d\u6bd4\u5982<code style=\"color: #2c3e50;\">json<\/code>\uff0c\u4e00\u4e2a\u9017\u53f7\u5206\u9694\u7684\u5217\u8868\uff0c\u6216\u8005\u4e00\u4e2a\u6570\u7ec4\u3002\u5bf9\u4e8e\u4e00\u4e2a\u5217\u8868\u6216\u8005\u6570\u7ec4\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u8fd4\u56de\u6700\u4f73\u9879(\u5982\u679c\u6709\u7684\u8bdd)\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ Accept: text\/html<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">accepts<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'html'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"html\"<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ Accept: text\/*, application\/json<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">accepts<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'html'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"html\"<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">accepts<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'text\/html'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"text\/html\"<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">accepts<\/span><span class=\"pun\" style=\"color: #666600;\">([<\/span><span class=\"str\" style=\"color: #008800;\">'json'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'text'<\/span><span class=\"pun\" style=\"color: #666600;\">]);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"json\"<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">accepts<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'application\/json'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"application\/json\"<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ Accept: text\/*, application\/json<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">accepts<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'image\/png'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">accepts<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'png'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; undefined<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ Accept: text\/*;q=.5, application\/json<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">accepts<\/span><span class=\"pun\" style=\"color: #666600;\">([<\/span><span class=\"str\" style=\"color: #008800;\">'html'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'json'<\/span><span class=\"pun\" style=\"color: #666600;\">]);<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"json\"<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"h318\">\u83b7\u53d6\u66f4\u591a\u4fe1\u606f\uff0c\u6216\u8005\u5982\u679c\u4f60\u6709\u95ee\u9898\u6216\u5173\u6ce8\uff0c\u53ef\u4ee5\u53c2\u9605<a style=\"color: #0088cc;\" href=\"https:\/\/github.com\/expressjs\/accepts?_ga=1.88139675.1201680737.1446005628\" target=\"_blank\">accepts<\/a>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqacceptscharsetscharset\" style=\"color: #2c3e50;\" data-anchor-id=\"7lha\">req.acceptsCharsets(charset[, &#8230;])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"rzd0\">\u8fd4\u56de\u6307\u5b9a\u7684\u5b57\u7b26\u96c6\u96c6\u5408\u4e2d\u7b2c\u4e00\u4e2a\u7684\u914d\u7f6e\u7684\u5b57\u7b26\u96c6\uff0c\u57fa\u4e8e\u8bf7\u6c42\u7684<code style=\"color: #2c3e50;\">Accept-Charset<\/code>HTTP\u5934\u3002\u5982\u679c\u6307\u5b9a\u7684\u5b57\u7b26\u96c6\u6ca1\u6709\u5339\u914d\u7684\uff0c\u90a3\u4e48\u5c31\u8fd4\u56defalse\u3002<br \/>\n\u83b7\u53d6\u66f4\u591a\u4fe1\u606f\uff0c\u6216\u8005\u5982\u679c\u4f60\u6709\u95ee\u9898\u6216\u5173\u6ce8\uff0c\u53ef\u4ee5\u53c2\u9605<a style=\"color: #0088cc;\" href=\"https:\/\/github.com\/expressjs\/accepts?_ga=1.88139675.1201680737.1446005628\" target=\"_blank\">accepts<\/a>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqacceptsencodingsencoding\" style=\"color: #2c3e50;\" data-anchor-id=\"pb6p\">req.acceptsEncodings(encoding[, &#8230;])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"62e2\">\u8fd4\u56de\u6307\u5b9a\u7684\u7f16\u7801\u96c6\u5408\u4e2d\u7b2c\u4e00\u4e2a\u7684\u914d\u7f6e\u7684\u7f16\u7801\uff0c\u57fa\u4e8e\u8bf7\u6c42\u7684<code style=\"color: #2c3e50;\">Accept-Encoding<\/code>HTTP\u5934\u3002\u5982\u679c\u6307\u5b9a\u7684\u7f16\u7801\u96c6\u6ca1\u6709\u5339\u914d\u7684\uff0c\u90a3\u4e48\u5c31\u8fd4\u56defalse\u3002<br \/>\n\u83b7\u53d6\u66f4\u591a\u4fe1\u606f\uff0c\u6216\u8005\u5982\u679c\u4f60\u6709\u95ee\u9898\u6216\u5173\u6ce8\uff0c\u53ef\u4ee5\u53c2\u9605<a style=\"color: #0088cc;\" href=\"https:\/\/github.com\/expressjs\/accepts?_ga=1.88139675.1201680737.1446005628\" target=\"_blank\">accepts<\/a>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqacceptslanguageslang\" style=\"color: #2c3e50;\" data-anchor-id=\"sv6a\">req.acceptsLanguages(lang [, &#8230;])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"m05s\">\u8fd4\u56de\u6307\u5b9a\u7684\u8bed\u8a00\u96c6\u5408\u4e2d\u7b2c\u4e00\u4e2a\u7684\u914d\u7f6e\u7684\u8bed\u8a00\uff0c\u57fa\u4e8e\u8bf7\u6c42\u7684<code style=\"color: #2c3e50;\">Accept-Language<\/code>HTTP\u5934\u3002\u5982\u679c\u6307\u5b9a\u7684\u8bed\u8a00\u96c6\u6ca1\u6709\u5339\u914d\u7684\uff0c\u90a3\u4e48\u5c31\u8fd4\u56defalse\u3002<br \/>\n\u83b7\u53d6\u66f4\u591a\u4fe1\u606f\uff0c\u6216\u8005\u5982\u679c\u4f60\u6709\u95ee\u9898\u6216\u5173\u6ce8\uff0c\u53ef\u4ee5\u53c2\u9605<a style=\"color: #0088cc;\" href=\"https:\/\/github.com\/expressjs\/accepts?_ga=1.88139675.1201680737.1446005628\" target=\"_blank\">accepts<\/a>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqgetfield\" style=\"color: #2c3e50;\" data-anchor-id=\"515i\">req.get(field)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"hzl0\">\u8fd4\u56de\u6307\u5b9a\u7684\u8bf7\u6c42HTTP\u5934\u90e8\u7684\u57df\u5185\u5bb9(\u4e0d\u533a\u5206\u5927\u5c0f\u5199)\u3002<code style=\"color: #2c3e50;\">Referrer<\/code>\u548c<code style=\"color: #2c3e50;\">Referer<\/code>\u7684\u57df\u5185\u5bb9\u53ef\u4e92\u6362\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Content-type'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"text\/plain\"<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'content-type'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"text\/plain\"<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Something'<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; undefined<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"24a8\">\u5176\u662f<code style=\"color: #2c3e50;\">req.header(field)<\/code>\u7684\u522b\u540d\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqistype\" style=\"color: #2c3e50;\" data-anchor-id=\"g7wi\">req.is(type)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"w4dj\">\u5982\u679c\u8fdb\u6765\u7684\u8bf7\u6c42\u7684<code style=\"color: #2c3e50;\">Content-type<\/code>\u5934\u90e8\u57df\u5339\u914d\u53c2\u6570<code style=\"color: #2c3e50;\">type<\/code>\u7ed9\u5b9a\u7684<code style=\"color: #2c3e50;\">MIME type<\/code>\uff0c\u90a3\u4e48\u5176\u8fd4\u56de<code style=\"color: #2c3e50;\">true<\/code>\u3002\u5426\u5219\u8fd4\u56de<code style=\"color: #2c3e50;\">false<\/code>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ With Content-Type: text\/html; charset=utf-8<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">is<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'html'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">is<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'text\/html'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">is<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'text\/*'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; true<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ When Content-Type is application\/json<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">is<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'json'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">is<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'application\/json'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">is<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'application\/*'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; true<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">is<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'html'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; false<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"0j7i\">\u83b7\u53d6\u66f4\u591a\u4fe1\u606f\uff0c\u6216\u8005\u5982\u679c\u4f60\u6709\u95ee\u9898\u6216\u5173\u6ce8\uff0c\u53ef\u4ee5\u53c2\u9605<a style=\"color: #0088cc;\" href=\"https:\/\/github.com\/expressjs\/type-is?_ga=1.33770401.1201680737.1446005628\" target=\"_blank\">type-is<\/a>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reqparamnaem-defaultvalue\" style=\"color: #2c3e50;\" data-anchor-id=\"jp8i\">req.param(naem, [, defaultValue])<\/h4>\n<blockquote class=\"white-blockquote\" style=\"color: #2c3e50;\" data-anchor-id=\"15xe\">\n<p style=\"font-weight: 300;\">\u8fc7\u65f6\u7684\u3002\u53ef\u4ee5\u5728\u9002\u5408\u7684\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528<code style=\"color: #2c3e50;\">req.params<\/code>\uff0c<code style=\"color: #2c3e50;\">req.body<\/code>\u6216\u8005<code style=\"color: #2c3e50;\">req.query<\/code>\u3002<\/p>\n<\/blockquote>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"ksor\">\u8fd4\u56de\u5f53\u524d\u53c2\u6570<code style=\"color: #2c3e50;\">name<\/code>\u7684\u503c\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ ?name=tobi<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">param<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'name'<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"tobi\"<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ POST name=tobi<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">param<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'name'<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"tobi\"<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ \/user\/tobi for \/user\/:name<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">param<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'name'<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"tobi\"<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"cmnf\">\u6309\u4e0b\u9762\u7ed9\u51fa\u7684\u987a\u5e8f\u67e5\u627e\uff1a<\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li style=\"color: #2c3e50;\" data-anchor-id=\"yb6a\">req.params<\/li>\n<li style=\"color: #2c3e50;\" data-anchor-id=\"2n9l\">req.body<\/li>\n<li style=\"color: #2c3e50;\" data-anchor-id=\"hn7c\">req.query<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"fhkz\">\u53ef\u9009\u7684\uff0c\u4f60\u53ef\u4ee5\u6307\u5b9a\u4e00\u4e2a<code style=\"color: #2c3e50;\">defaultValue<\/code>\u6765\u8bbe\u7f6e\u4e00\u4e2a\u9ed8\u8ba4\u503c\uff0c\u5982\u679c\u8fd9\u4e2a\u53c2\u6570\u5728\u4efb\u4f55\u4e00\u4e2a\u8bf7\u6c42\u7684\u5bf9\u8c61\u4e2d\u90fd\u4e0d\u80fd\u627e\u5230\u3002<\/p>\n<blockquote class=\"white-blockquote\" style=\"color: #2c3e50;\" data-anchor-id=\"1t9t\">\n<p style=\"font-weight: 300;\">\u76f4\u63a5\u901a\u8fc7<code style=\"color: #2c3e50;\">req.params<\/code>\uff0c<code style=\"color: #2c3e50;\">req.body<\/code>\uff0c<code style=\"color: #2c3e50;\">req.query<\/code>\u53d6\u5f97\u5e94\u8be5\u66f4\u52a0\u7684\u6e05\u6670-\u9664\u975e\u4f60\u786e\u5b9a\u6bcf\u4e00\u4e2a\u5bf9\u8c61\u7684\u8f93\u5165\u3002<br \/>\n<code style=\"color: #2c3e50;\">Body-parser<\/code>\u4e2d\u95f4\u4ef6\u5fc5\u987b\u52a0\u8f7d\uff0c\u5982\u679c\u4f60\u4f7f\u7528<code style=\"color: #2c3e50;\">req.param()<\/code>\u3002\u8be6\u7ec6\u8bf7\u770b<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#req.body\" target=\"_blank\">req.body<\/a>\u3002<\/p>\n<\/blockquote>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h2 id=\"response\" style=\"color: #2c3e50;\" data-anchor-id=\"jx1d\">Response<\/h2>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"0wlk\"><code style=\"color: #2c3e50;\">res<\/code>\u5bf9\u8c61\u4ee3\u8868\u4e86\u5f53\u4e00\u4e2aHTTP\u8bf7\u6c42\u5230\u6765\u65f6\uff0c<code style=\"color: #2c3e50;\">Express<\/code>\u7a0b\u5e8f\u8fd4\u56de\u7684HTTP\u54cd\u5e94\u3002\u5728\u672c\u6587\u6863\u4e2d\uff0c\u6309\u7167\u60ef\u4f8b\uff0c\u8fd9\u4e2a\u5bf9\u8c61\u603b\u662f\u7b80\u79f0\u4e3a<code style=\"color: #2c3e50;\">res<\/code>(http\u8bf7\u6c42\u7b80\u79f0\u4e3a<code style=\"color: #2c3e50;\">req<\/code>)\uff0c\u4f46\u662f\u5b83\u4eec\u5b9e\u9645\u7684\u540d\u5b57\u7531\u8fd9\u4e2a\u56de\u8c03\u65b9\u6cd5\u5728\u90a3\u91cc\u4f7f\u7528\u65f6\u7684\u53c2\u6570\u51b3\u5b9a\u3002<br \/>\n\u4f8b\u5982\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/user\/:id'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'user'<\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"pln\" style=\"color: #000000;\"> req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">params<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">id<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"hn93\">\u8fd9\u6837\u5199\u4e5f\u662f\u4e00\u6837\u7684\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/user\/:id'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">request<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> response<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> response<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'user'<\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"pln\" style=\"color: #000000;\"> request<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">params<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">id<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h3 id=\"properties-2\" style=\"color: #2c3e50;\" data-anchor-id=\"k6bd\">Properties<\/h3>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"resapp\" style=\"color: #2c3e50;\" data-anchor-id=\"ch1j\">res.app<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"8m5i\">\u8fd9\u4e2a\u5c5e\u6027\u6301\u6709<code style=\"color: #2c3e50;\">express<\/code>\u7a0b\u5e8f\u5b9e\u4f8b\u7684\u4e00\u4e2a\u5f15\u7528\uff0c\u5176\u53ef\u4ee5\u5728\u4e2d\u95f4\u4ef6\u4e2d\u4f7f\u7528\u3002<br \/>\n<code style=\"color: #2c3e50;\">res.app<\/code>\u548c\u8bf7\u6c42\u5bf9\u8c61\u4e2d\u7684<code style=\"color: #2c3e50;\">req.app<\/code>\u5c5e\u6027\u662f\u76f8\u540c\u7684\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"resheaderssent\" style=\"color: #2c3e50;\" data-anchor-id=\"ll6j\">res.headersSent<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"ehe8\">\u5e03\u5c14\u7c7b\u578b\u7684\u5c5e\u6027\uff0c\u6307\u793a\u8fd9\u4e2a\u54cd\u5e94\u662f\u5426\u5df2\u7ecf\u53d1\u9001HTTP\u5934\u90e8\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">headersSent<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ false<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'OK'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ send\u4e4b\u540e\u5c31\u53d1\u9001\u4e86\u5934\u90e8<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">headersSent<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ true<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reslocals\" style=\"color: #2c3e50;\" data-anchor-id=\"qmpp\">res.locals<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"zq9q\">\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5176\u5305\u542b\u4e86\u54cd\u5e94\u7684\u80fd\u591f\u53cd\u5e94\u51fa\u8bf7\u6c42\u7684\u672c\u5730\u53c2\u6570\u548c\u56e0\u6b64\u53ea\u63d0\u4f9b\u7ed9\u89c6\u56fe\u6e32\u67d3\uff0c\u5728\u8bf7\u6c42\u54cd\u5e94\u7684\u5468\u671f\u5185(\u5982\u679c\u6709\u7684\u8bdd)&#8211;\u6211\u8981\u7ffb\u8bd1\u5410\u4e86\u3002\u5426\u5219\uff0c\u5176\u548c<code style=\"color: #2c3e50;\">app.locals<\/code>\u662f\u4e00\u6837\u7684\u3002(\u4e0d\u77e5\u9053\u7ffb\u8bd1\u7684\u4ec0\u4e48&#8230;)<br \/>\n\u8fd9\u4e2a\u53c2\u6570\u5728\u5bfc\u51fa\u8bf7\u6c42\u7ea7\u522b\u7684\u4fe1\u606f\u662f\u5f88\u6709\u6548\u7684\uff0c\u8fd9\u4e9b\u4fe1\u606f\u6bd4\u5982\u8bf7\u6c42\u8def\u5f84\uff0c\u5df2\u8ba4\u8bc1\u7684\u7528\u6237\uff0c\u7528\u6237\u8bbe\u7f6e\u7b49\u7b49\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">locals<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">user <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">user<\/span><span class=\"pun\" style=\"color: #666600;\">;<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">locals<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">authenticated <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pun\" style=\"color: #666600;\">!<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">user<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">anonymous<\/span><span class=\"pun\" style=\"color: #666600;\">;<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h3 id=\"methods-3\" style=\"color: #2c3e50;\" data-anchor-id=\"wqvr\">Methods<\/h3>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"resappendfield-value\" style=\"color: #2c3e50;\" data-anchor-id=\"i0g3\">res.append(field [, value])<\/h4>\n<blockquote class=\"white-blockquote\" style=\"color: #2c3e50;\" data-anchor-id=\"3xo8\">\n<p style=\"font-weight: 300;\">res.append()\u65b9\u6cd5\u5728<code style=\"color: #2c3e50;\">Expresxs<\/code>4.11.0\u4ee5\u4e0a\u7248\u672c\u624d\u652f\u6301\u3002<\/p>\n<\/blockquote>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"vsyz\">\u5728\u6307\u5b9a\u7684<code style=\"color: #2c3e50;\">field<\/code>\u7684HTTP\u5934\u90e8\u8ffd\u52a0\u7279\u6b8a\u7684\u503c<code style=\"color: #2c3e50;\">value<\/code>\u3002\u5982\u679c\u8fd9\u4e2a\u5934\u90e8\u6ca1\u6709\u88ab\u8bbe\u7f6e\uff0c\u90a3\u4e48\u5c06\u7528<code style=\"color: #2c3e50;\">value<\/code>\u65b0\u5efa\u8fd9\u4e2a\u5934\u90e8\u3002<code style=\"color: #2c3e50;\">value<\/code>\u53ef\u4ee5\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u6216\u8005\u6570\u7ec4\u3002<br \/>\n\u6ce8\u610f\uff1a\u5728<code style=\"color: #2c3e50;\">res.append()<\/code>\u4e4b\u540e\u8c03\u7528<code style=\"color: #2c3e50;\">app.set()<\/code>\u51fd\u6570\u5c06\u91cd\u7f6e\u524d\u9762\u8bbe\u7f6e\u7684\u503c\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">append<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Lind'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pun\" style=\"color: #666600;\">[<\/span><span class=\"str\" style=\"color: #008800;\">'&lt;http:\/\/localhost&gt;'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'&lt;http:\/\/localhost:3000&gt;'<\/span><span class=\"pun\" style=\"color: #666600;\">]);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">append<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Set-Cookie'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'foo=bar;Path=\/;HttpOnly'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">append<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Warning'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'199 Miscellaneous warning'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"resattachmentfilename\" style=\"color: #2c3e50;\" data-anchor-id=\"nuvg\">res.attachment([filename])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"fy4c\">\u8bbe\u7f6eHTTP\u54cd\u5e94\u7684<code style=\"color: #2c3e50;\">Content-Disposition<\/code>\u5934\u5185\u5bb9\u4e3a&#8221;attachment&#8221;\u3002\u5982\u679c\u63d0\u4f9b\u4e86<code style=\"color: #2c3e50;\">filename<\/code>\uff0c\u90a3\u4e48\u5c06\u901a\u8fc7<code style=\"color: #2c3e50;\">res.type()<\/code>\u83b7\u5f97\u6269\u5c55\u540d\u6765\u8bbe\u7f6e<code style=\"color: #2c3e50;\">Content-Type<\/code>\uff0c\u5e76\u4e14\u8bbe\u7f6e<code style=\"color: #2c3e50;\">Content-Disposition<\/code>\u5185\u5bb9\u4e3a&#8221;filename=&#8221;parameter\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">attachment<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ Content-Disposition: attachment<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">attachment<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'path\/to\/logo.png'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ Content-Disposition: attachment; filename=\"logo.png\"<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ Content-Type: image\/png<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"rescookiename-value-options\" style=\"color: #2c3e50;\" data-anchor-id=\"dapy\">res.cookie(name, value [,options])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"6hg7\">\u8bbe\u7f6e<code style=\"color: #2c3e50;\">name<\/code>\u548c<code style=\"color: #2c3e50;\">value<\/code>\u7684<code style=\"color: #2c3e50;\">cookie<\/code>\uff0c<code style=\"color: #2c3e50;\">value<\/code>\u53c2\u6570\u53ef\u4ee5\u662f\u4e00\u4e32\u5b57\u7b26\u6216\u8005\u662f\u8f6c\u5316\u4e3ajson\u5b57\u7b26\u4e32\u7684\u5bf9\u8c61\u3002<br \/>\noptions\u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5176\u53ef\u4ee5\u6709\u4e0b\u5217\u7684\u5c5e\u6027\u3002<\/p>\n<table class=\"table table-striped-white table-bordered\" style=\"color: #2c3e50;\" data-anchor-id=\"19uv\">\n<thead>\n<tr>\n<th style=\"font-weight: bold;\">\u5c5e\u6027<\/th>\n<th style=\"font-weight: bold;\">\u7c7b\u578b<\/th>\n<th style=\"font-weight: bold;\">\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>domain<\/td>\n<td>String<\/td>\n<td>\u8bbe\u7f6ecookie\u7684\u57df\u540d\u3002\u9ed8\u8ba4\u662f\u4f60\u672capp\u7684\u57df\u540d\u3002<\/td>\n<\/tr>\n<tr>\n<td>expires<\/td>\n<td>Date<\/td>\n<td>cookie\u7684\u8fc7\u671f\u65f6\u95f4\uff0cGMT\u683c\u5f0f\u3002\u5982\u679c\u6ca1\u6709\u6307\u5b9a\u6216\u8005\u8bbe\u7f6e\u4e3a0\uff0c\u5219\u4ea7\u751f\u65b0\u7684cookie\u3002<\/td>\n<\/tr>\n<tr>\n<td>httpOnly<\/td>\n<td>Boolean<\/td>\n<td>\u8fd9\u4e2acookie\u53ea\u80fd\u88abweb\u670d\u52a1\u5668\u83b7\u53d6\u7684\u6807\u793a\u3002<\/td>\n<\/tr>\n<tr>\n<td>maxAge<\/td>\n<td>String<\/td>\n<td>\u662f\u8bbe\u7f6e\u8fc7\u53bb\u65f6\u95f4\u7684\u65b9\u4fbf\u9009\u9879\uff0c\u5176\u4e3a\u8fc7\u671f\u65f6\u95f4\u5230\u5f53\u524d\u65f6\u95f4\u7684\u6beb\u79d2\u503c\u3002<\/td>\n<\/tr>\n<tr>\n<td>path<\/td>\n<td>String<\/td>\n<td>cookie\u7684\u8def\u5f84\u3002\u9ed8\u8ba4\u503c\u662f<code style=\"color: #2c3e50;\">\/<\/code>\u3002<\/td>\n<\/tr>\n<tr>\n<td>secure<\/td>\n<td>Boolean<\/td>\n<td>\u6807\u793a\u8fd9\u4e2acookie\u53ea\u7528\u88ab<code style=\"color: #2c3e50;\">HTTPS<\/code>\u534f\u8bae\u4f7f\u7528\u3002<\/td>\n<\/tr>\n<tr>\n<td>signed<\/td>\n<td>Boolean<\/td>\n<td>\u6307\u793a\u8fd9\u4e2acookie\u5e94\u8be5\u662f\u7b7e\u540d\u7684\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<blockquote class=\"white-blockquote\" style=\"color: #2c3e50;\" data-anchor-id=\"wurn\">\n<p style=\"font-weight: 300;\">res.cookie()\u6240\u4f5c\u7684\u90fd\u662f\u57fa\u4e8e\u63d0\u4f9b\u7684<code style=\"color: #2c3e50;\">options<\/code>\u53c2\u6570\u6765\u8bbe\u7f6e<code style=\"color: #2c3e50;\">Set-Cookie<\/code>\u5934\u90e8\u3002\u6ca1\u6709\u6307\u5b9a\u4efb\u4f55\u7684<code style=\"color: #2c3e50;\">options<\/code>\uff0c\u90a3\u4e48\u9ed8\u8ba4\u503c\u5728<code style=\"color: #2c3e50;\">RFC6265<\/code>\u4e2d\u6307\u5b9a\u3002<\/p>\n<\/blockquote>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"ht64\">\u4f7f\u7528\u5b9e\u4f8b\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">cookie<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'name'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'tobi'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><span class=\"str\" style=\"color: #008800;\">'domain'<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'.example.com'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'path'<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'\/admin'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'secure'<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"kwd\" style=\"color: #000088;\">true<\/span><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">cookie<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'remenberme'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'1'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><span class=\"str\" style=\"color: #008800;\">'expires'<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"kwd\" style=\"color: #000088;\">new<\/span><span class=\"typ\" style=\"color: #660066;\">Date<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"typ\" style=\"color: #660066;\">Date<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">now<\/span><span class=\"pun\" style=\"color: #666600;\">()<\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"lit\" style=\"color: #006666;\">90000<\/span><span class=\"pun\" style=\"color: #666600;\">),<\/span><span class=\"str\" style=\"color: #008800;\">'httpOnly'<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"kwd\" style=\"color: #000088;\">true<\/span><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"ejdr\"><code style=\"color: #2c3e50;\">maxAge<\/code>\u662f\u4e00\u4e2a\u65b9\u4fbf\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\u7684\u65b9\u4fbf\u7684\u9009\u9879\uff0c\u5176\u4ee5\u5f53\u524d\u65f6\u95f4\u5f00\u59cb\u7684\u6beb\u79d2\u6570\u6765\u8ba1\u7b97\u3002\u4e0b\u9762\u7684\u793a\u4f8b\u548c\u4e0a\u9762\u7684\u7b2c\u4e8c\u6761\u529f\u6548\u4e00\u6837\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">cookie<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'rememberme'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'1'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><span class=\"str\" style=\"color: #008800;\">'masAge'<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"lit\" style=\"color: #006666;\">90000<\/span><span class=\"pun\" style=\"color: #666600;\">},<\/span><span class=\"str\" style=\"color: #008800;\">\"httpOnly\"<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"kwd\" style=\"color: #000088;\">true<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"4xac\">\u4f60\u53ef\u4ee5\u8bbe\u7f6e\u4f20\u9012\u4e00\u4e2a\u5bf9\u8c61\u4f5c\u4e3a<code style=\"color: #2c3e50;\">value<\/code>\u7684\u53c2\u6570\u3002\u7136\u540e\u5176\u5c06\u88ab\u5e8f\u5217\u5316\u4e3aJson\u5b57\u7b26\u4e32\uff0c\u88ab<code style=\"color: #2c3e50;\">bodyParser()<\/code>\u4e2d\u95f4\u4ef6\u89e3\u6790\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">cookie<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'cart'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><span class=\"str\" style=\"color: #008800;\">'items'<\/span><span class=\"pun\" style=\"color: #666600;\">:[<\/span><span class=\"lit\" style=\"color: #006666;\">1<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"lit\" style=\"color: #006666;\">2<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"lit\" style=\"color: #006666;\">3<\/span><span class=\"pun\" style=\"color: #666600;\">]});<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">cookie<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'cart'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><span class=\"str\" style=\"color: #008800;\">'items'<\/span><span class=\"pun\" style=\"color: #666600;\">:[<\/span><span class=\"lit\" style=\"color: #006666;\">1<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"lit\" style=\"color: #006666;\">2<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"lit\" style=\"color: #006666;\">3<\/span><span class=\"pun\" style=\"color: #666600;\">]},<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><span class=\"str\" style=\"color: #008800;\">'maxAge'<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"lit\" style=\"color: #006666;\">90000<\/span><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"auy4\">\u5f53\u6211\u4eec\u4f7f\u7528<code style=\"color: #2c3e50;\">cookie-parser<\/code>\u4e2d\u95f4\u4ef6\u7684\u65f6\u5019\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u4e5f\u652f\u6301\u7b7e\u540d\u7684cookie\u3002\u7b80\u5355\u5730\uff0c\u5728\u8bbe\u7f6e<code style=\"color: #2c3e50;\">options<\/code>\u65f6\u5305\u542b<code style=\"color: #2c3e50;\">signed<\/code>\u9009\u9879\u4e3a<code style=\"color: #2c3e50;\">true<\/code>\u3002\u7136\u540e<code style=\"color: #2c3e50;\">res.cookie()<\/code>\u5c06\u4f7f\u7528\u4f20\u9012\u7ed9<code style=\"color: #2c3e50;\">cookieParser(secret)<\/code>\u7684\u5bc6\u94a5\u6765\u7b7e\u540d\u8fd9\u4e2a\u503c\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">cookie<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'name'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'tobi'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><span class=\"str\" style=\"color: #008800;\">'signed'<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"kwd\" style=\"color: #000088;\">true<\/span><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"resclearcookiename-options\" style=\"color: #2c3e50;\" data-anchor-id=\"gfmq\">res.clearCookie(name [,options])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"2w3e\">\u6839\u636e\u6307\u5b9a\u7684<code style=\"color: #2c3e50;\">name<\/code>\u6e05\u9664\u5bf9\u5e94\u7684cookie\u3002\u66f4\u591a\u5173\u4e8e<code style=\"color: #2c3e50;\">options<\/code>\u5bf9\u8c61\u53ef\u4ee5\u67e5\u9605<code style=\"color: #2c3e50;\">res.cookie()<\/code>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">cookie<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'name'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'tobi'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><span class=\"str\" style=\"color: #008800;\">'path'<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'\/admin'<\/span><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">clearCookie<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'name'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><span class=\"str\" style=\"color: #008800;\">'path'<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'admin'<\/span><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"resdownloadpath-filename-fn\" style=\"color: #2c3e50;\" data-anchor-id=\"lw8g\">res.download(path, [,filename], [,fn])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"8dor\">\u4f20\u8f93<code style=\"color: #2c3e50;\">path<\/code>\u6307\u5b9a\u6587\u4ef6\u4f5c\u4e3a\u4e00\u4e2a\u9644\u4ef6\u3002\u901a\u5e38\uff0c\u6d4f\u89c8\u5668\u63d0\u793a\u7528\u6237\u4e0b\u8f7d\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c<code style=\"color: #2c3e50;\">Content-Disposition<\/code>\u5934\u90e8&#8221;filename=&#8221;\u7684\u53c2\u6570\u4e3a<code style=\"color: #2c3e50;\">path<\/code>(\u901a\u5e38\u4f1a\u51fa\u73b0\u5728\u6d4f\u89c8\u5668\u7684\u5bf9\u8bdd\u6846\u4e2d)\u3002\u901a\u8fc7\u6307\u5b9a<code style=\"color: #2c3e50;\">filename<\/code>\u53c2\u6570\u6765\u8986\u76d6\u9ed8\u8ba4\u503c\u3002<br \/>\n\u5f53\u4e00\u4e2a\u9519\u8bef\u53d1\u751f\u65f6\u6216\u8005\u4f20\u8f93\u5b8c\u6210\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u5c06\u8c03\u7528<code style=\"color: #2c3e50;\">fn<\/code>\u6307\u5b9a\u7684\u56de\u8c03\u65b9\u6cd5\u3002\u8fd9\u4e2a\u65b9\u6cd5\u4f7f\u7528<code style=\"color: #2c3e50;\">res.sendFile()<\/code>\u6765\u4f20\u8f93\u6587\u4ef6\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">download<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/report-12345.pdf'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">download<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/report-12345.pdf'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'report.pdf'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">download<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'report-12345.pdf'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'report.pdf'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">err<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ Handle error, but keep in mind the response may be partially-sent<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ so check res.headersSent<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">if<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">err<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><span class=\"kwd\" style=\"color: #000088;\">else<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ decrement a download credit, etc.<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"resenddata-encoding\" style=\"color: #2c3e50;\" data-anchor-id=\"y5dp\">res.end([data] [, encoding])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"rpzu\">\u7ed3\u675f\u672c\u54cd\u5e94\u7684\u8fc7\u7a0b\u3002\u8fd9\u4e2a\u65b9\u6cd5\u5b9e\u9645\u4e0a\u6765\u81ea<code style=\"color: #2c3e50;\">Node<\/code>\u6838\u5fc3\u6a21\u5757\uff0c\u5177\u4f53\u7684\u662f<a style=\"color: #0088cc;\" href=\"https:\/\/nodejs.org\/api\/http.html#http_response_end_data_encoding_callback\" target=\"_blank\">response.end() method of http.ServerResponse<\/a>\u3002<br \/>\n\u7528\u6765\u5feb\u901f\u7ed3\u675f\u8bf7\u6c42\uff0c\u6ca1\u6709\u4efb\u4f55\u7684\u6570\u636e\u3002\u5982\u679c\u4f60\u9700\u8981\u53d1\u9001\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#res.send\" target=\"_blank\">res.send()<\/a>\u548c<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#res.json\" target=\"_blank\">res.json()<\/a>\u8fd9\u7c7b\u7684\u65b9\u6cd5\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">end<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">status<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">404<\/span><span class=\"pun\" style=\"color: #666600;\">).<\/span><span class=\"pln\" style=\"color: #000000;\">end<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"resformatobject\" style=\"color: #2c3e50;\" data-anchor-id=\"50sm\">res.format(object)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"hjjd\">\u8fdb\u884c\u5185\u5bb9\u534f\u5546\uff0c\u6839\u636e\u8bf7\u6c42\u7684\u5bf9\u8c61\u4e2d<code style=\"color: #2c3e50;\">Accept<\/code>HTTP\u5934\u90e8\u6307\u5b9a\u7684\u63a5\u53d7\u5185\u5bb9\u3002\u5b83\u4f7f\u7528<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#req.accepts\" target=\"_blank\">req.accepts()<\/a>\u6765\u9009\u62e9\u4e00\u4e2a\u53e5\u67c4\u6765\u4e3a\u8bf7\u6c42\u670d\u52a1\uff0c\u8fd9\u4e9b\u53e5\u67c4\u6309\u8d28\u91cf\u503c\u8fdb\u884c\u6392\u5e8f\u3002\u5982\u679c\u8fd9\u4e2a\u5934\u90e8\u6ca1\u6709\u6307\u5b9a\uff0c\u90a3\u4e48\u7b2c\u4e00\u4e2a\u65b9\u6cd5\u9ed8\u8ba4\u88ab\u8c03\u7528\u3002\u5f53\u4e0d\u5339\u914d\u65f6\uff0c\u670d\u52a1\u5668\u5c06\u8fd4\u56de<code style=\"color: #2c3e50;\">406<\/code>&#8220;Not Acceptable&#8221;\uff0c\u6216\u8005\u8c03\u7528<code style=\"color: #2c3e50;\">default<\/code>\u56de\u8c03\u3002<br \/>\n<code style=\"color: #2c3e50;\">Content-Type<\/code>\u8bf7\u6c42\u5934\u88ab\u8bbe\u7f6e\uff0c\u5f53\u4e00\u4e2a\u56de\u8c03\u65b9\u6cd5\u88ab\u9009\u62e9\u3002\u7136\u800c\u4f60\u53ef\u4ee5\u6539\u53d8\u4ed6\uff0c\u5728\u8fd9\u4e2a\u65b9\u6cd5\u4e2d\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u6bd4\u5982<code style=\"color: #2c3e50;\">res.set()<\/code>\u6216\u8005<code style=\"color: #2c3e50;\">res.type()<\/code>\u3002<br \/>\n\u4e0b\u9762\u7684\u4f8b\u5b50\uff0c\u5c06\u56de\u590d<code style=\"color: #2c3e50;\">{\"message\":\"hey\"}<\/code>\uff0c\u5f53\u8bf7\u6c42\u7684\u5bf9\u8c61\u4e2d<code style=\"color: #2c3e50;\">Accept<\/code>\u5934\u90e8\u8bbe\u7f6e\u6210&#8221;application\/json&#8221;\u6216\u8005&#8221;*\/json&#8221;(\u4e0d\u8fc7\u5982\u679c\u662f<code style=\"color: #2c3e50;\">*\/*<\/code>\uff0c\u7136\u540e\u8fd9\u4e2a\u56de\u590d\u5c31\u662f&#8221;hey&#8221;)\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">format<\/span><span class=\"pun\" style=\"color: #666600;\">({<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"str\" style=\"color: #008800;\">'text\/plain'<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">()<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'hey'<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"str\" style=\"color: #008800;\">'<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">},<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"str\" style=\"color: #008800;\">'text\/html'<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">()<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'&lt;p&gt;hey&lt;\/p&gt;'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">},<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"str\" style=\"color: #008800;\">'application\/json'<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">()<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">({<\/span><span class=\"pln\" style=\"color: #000000;\">message<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'hey'<\/span><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">},<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"str\" style=\"color: #008800;\">'default'<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">()<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">status<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">406<\/span><span class=\"pun\" style=\"color: #666600;\">).<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Not Acceptable'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">})<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"kgjt\">\u9664\u4e86\u89c4\u8303\u5316\u7684MIME\u7c7b\u578b\u4e4b\u5916\uff0c\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u62d3\u5c55\u540d\u6765\u6620\u5c04\u8fd9\u4e9b\u7c7b\u578b\u6765\u907f\u514d\u5197\u957f\u7684\u5b9e\u73b0\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">format<\/span><span class=\"pun\" style=\"color: #666600;\">({<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> text<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">()<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'hey'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">},<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> html<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">()<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'&lt;p&gt;hey&lt;\/p&gt;'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">},<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> json<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">()<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">({<\/span><span class=\"pln\" style=\"color: #000000;\">message<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'hey'<\/span><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">})<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"resgetfield\" style=\"color: #2c3e50;\" data-anchor-id=\"8uja\">res.get(field)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"52s1\">\u8fd4\u56de<code style=\"color: #2c3e50;\">field<\/code>\u6307\u5b9a\u7684HTTP\u54cd\u5e94\u7684\u5934\u90e8\u3002\u5339\u914d\u662f\u533a\u5206\u5927\u5c0f\u5199\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Content-Type'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; \"text\/plain\"<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"resjsonbody\" style=\"color: #2c3e50;\" data-anchor-id=\"cp7d\">res.json([body])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"p5lb\">\u53d1\u9001\u4e00\u4e2ajson\u7684\u54cd\u5e94\u3002\u8fd9\u4e2a\u65b9\u6cd5\u548c\u5c06\u4e00\u4e2a\u5bf9\u8c61\u6216\u8005\u4e00\u4e2a\u6570\u7ec4\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9<code style=\"color: #2c3e50;\">res.send()<\/code>\u65b9\u6cd5\u7684\u6548\u679c\u76f8\u540c\u3002\u4e0d\u8fc7\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u65b9\u6cd5\u6765\u8f6c\u6362\u5176\u4ed6\u7684\u503c\u5230json\uff0c\u4f8b\u5982<code style=\"color: #2c3e50;\">null<\/code>\uff0c<code style=\"color: #2c3e50;\">undefined<\/code>\u3002(\u867d\u7136\u8fd9\u4e9b\u90fd\u662f\u6280\u672f\u4e0a\u65e0\u6548\u7684JSON)\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">json<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">null<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">json<\/span><span class=\"pun\" style=\"color: #666600;\">({<\/span><span class=\"pln\" style=\"color: #000000;\">user<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'tobi'<\/span><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">status<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">500<\/span><span class=\"pun\" style=\"color: #666600;\">).<\/span><span class=\"pln\" style=\"color: #000000;\">json<\/span><span class=\"pun\" style=\"color: #666600;\">({<\/span><span class=\"pln\" style=\"color: #000000;\">error<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'message'<\/span><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"resjsonpbody\" style=\"color: #2c3e50;\" data-anchor-id=\"4ifo\">res.jsonp([body])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"xgik\">\u53d1\u9001\u4e00\u4e2ajson\u7684\u54cd\u5e94\uff0c\u5e76\u4e14\u652f\u6301JSONP\u3002\u8fd9\u4e2a\u65b9\u6cd5\u548c<code style=\"color: #2c3e50;\">res.json()<\/code>\u6548\u679c\u76f8\u540c\uff0c\u9664\u4e86\u5176\u5728\u9009\u9879\u4e2d\u652f\u6301JSONP\u56de\u8c03\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">jsonp<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">null<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; null<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">jsonp<\/span><span class=\"pun\" style=\"color: #666600;\">({<\/span><span class=\"pln\" style=\"color: #000000;\">user<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'tobi'<\/span><span class=\"pun\" style=\"color: #666600;\">})<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; {\"user\" : \"tobi\"}<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">status<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">500<\/span><span class=\"pun\" style=\"color: #666600;\">).<\/span><span class=\"pln\" style=\"color: #000000;\">jsonp<\/span><span class=\"pun\" style=\"color: #666600;\">({<\/span><span class=\"pln\" style=\"color: #000000;\">error<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'message'<\/span><span class=\"pun\" style=\"color: #666600;\">})<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; {\"error\" : \"message\"}<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"g74k\">\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cjsonp\u7684\u56de\u8c03\u65b9\u6cd5\u7b80\u5355\u5199\u4f5c<code style=\"color: #2c3e50;\">callback<\/code>\u3002\u53ef\u4ee5\u901a\u8fc7<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/4x\/api.html#app.settings.table\" target=\"_blank\">jsonp callback name<\/a>\u8bbe\u7f6e\u6765\u91cd\u5199\u5b83\u3002<br \/>\n\u4e0b\u9762\u662f\u4e00\u4e9b\u4f8b\u5b50\u4f7f\u7528JSONP\u54cd\u5e94\uff0c\u4f7f\u7528\u76f8\u540c\u7684\u4ee3\u7801:<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ ?callback=foo<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">jsonp<\/span><span class=\"pun\" style=\"color: #666600;\">({<\/span><span class=\"pln\" style=\"color: #000000;\">user<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'tobo'<\/span><span class=\"pun\" style=\"color: #666600;\">})<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; foo({\"user\":\"tobi\"})<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">set<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'jsonp callback name'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'cb'<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ ?cb=foo<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">status<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">500<\/span><span class=\"pun\" style=\"color: #666600;\">).<\/span><span class=\"pln\" style=\"color: #000000;\">jsonp<\/span><span class=\"pun\" style=\"color: #666600;\">({<\/span><span class=\"pln\" style=\"color: #000000;\">error<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'message'<\/span><span class=\"pun\" style=\"color: #666600;\">})<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; foo({\"error\":\"message\"})<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reslinkslinks\" style=\"color: #2c3e50;\" data-anchor-id=\"oswv\">res.links(links)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"61qg\">\u8fde\u63a5\u8fd9\u4e9b<code style=\"color: #2c3e50;\">links<\/code>\uff0c<code style=\"color: #2c3e50;\">links<\/code>\u662f\u4ee5\u4f20\u5165\u53c2\u6570\u7684\u5c5e\u6027\u5f62\u5f0f\u63d0\u4f9b\uff0c\u8fde\u63a5\u4e4b\u540e\u7684\u5185\u5bb9\u7528\u6765\u586b\u5145\u54cd\u5e94\u7684Link HTTP\u5934\u90e8\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">links<\/span><span class=\"pun\" style=\"color: #666600;\">({<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'http:\/\/api.example.com\/users?page=2'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> last<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'http:\/\/api.example.com\/user?page=5'<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"v3x7\">\u6548\u679c\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"typ\" style=\"color: #660066;\">Link<\/span><span class=\"pun\" style=\"color: #666600;\">:&lt;<\/span><span class=\"pln\" style=\"color: #000000;\">http<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"com\" style=\"color: #880000;\">\/\/api.example.com\/users?page=2&gt;;rel=\"next\",<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">&lt;<\/span><span class=\"pln\" style=\"color: #000000;\">http<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"com\" style=\"color: #880000;\">\/\/api.example.com\/users?page=5&gt;;rel=\"last\"<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"reslocationpath\" style=\"color: #2c3e50;\" data-anchor-id=\"9rwc\">res.location(path)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"9p9n\">\u8bbe\u7f6e\u54cd\u5e94\u7684<code style=\"color: #2c3e50;\">Location<\/code>HTTP\u5934\u90e8\u4e3a\u6307\u5b9a\u7684<code style=\"color: #2c3e50;\">path<\/code>\u53c2\u6570\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">location<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/foo\/bar'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">location<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'http:\/\/example.com'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">location<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'back'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"93lt\">\u5f53<code style=\"color: #2c3e50;\">path<\/code>\u53c2\u6570\u4e3a<code style=\"color: #2c3e50;\">back<\/code>\u65f6\uff0c\u5176\u5177\u6709\u7279\u6b8a\u7684\u610f\u4e49\uff0c\u5176\u6307\u5b9aURL\u4e3a\u8bf7\u6c42\u5bf9\u8c61\u7684<code style=\"color: #2c3e50;\">Referer<\/code>\u5934\u90e8\u6307\u5b9a\u7684URL\u3002\u5982\u679c\u8bf7\u6c42\u4e2d\u6ca1\u6709\u6307\u5b9a\uff0c\u90a3\u4e48\u5176\u5373\u4e3a&#8221;\/&#8221;\u3002<\/p>\n<blockquote class=\"white-blockquote\" style=\"color: #2c3e50;\" data-anchor-id=\"6i3f\">\n<p style=\"font-weight: 300;\">Express\u4f20\u9012\u6307\u5b9a\u7684URL\u5b57\u7b26\u4e32\u4f5c\u4e3a\u56de\u590d\u7ed9\u6d4f\u89c8\u5668\u54cd\u5e94\u4e2d\u7684<code style=\"color: #2c3e50;\">Location<\/code>\u5934\u90e8\u7684\u503c\uff0c\u4e0d\u68c0\u6d4b\u548c\u64cd\u4f5c\uff0c\u9664\u4e86\u5f53\u662f<code style=\"color: #2c3e50;\">back<\/code>\u8fd9\u4e2acase\u65f6\u3002\u6d4f\u89c8\u5668\u6709\u63a8\u5bfc\u9884\u671fURL\u4ece\u5f53\u524d\u7684URL\u6216\u8005\u6307\u5b9a\u7684URL\uff0c\u548c\u5728<code style=\"color: #2c3e50;\">Location<\/code>\u6307\u5b9a\u7684URL\u7684\u8d23\u4efb\uff1b\u76f8\u5e94\u5730\u91cd\u5b9a\u5411\u5b83\u3002(\u6211\u4e5f\u4e0d\u77e5\u9053\u7ffb\u8bd1\u7684\u4ec0\u4e48&#8230;)<\/p>\n<\/blockquote>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"resredirectstatus-path\" style=\"color: #2c3e50;\" data-anchor-id=\"9yig\">res.redirect([status,] path)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"jczy\">\u91cd\u5b9a\u5411\u6765\u6e90\u4e8e\u6307\u5b9a<code style=\"color: #2c3e50;\">path<\/code>\u7684URL\uff0c\u4ee5\u53ca\u6307\u5b9a\u7684<a style=\"color: #0088cc;\" href=\"http:\/\/www.w3.org\/Protocols\/rfc2616\/rfc2616-sec10.html\" target=\"_blank\">HTTP status code<\/a><code style=\"color: #2c3e50;\">status<\/code>\u3002\u5982\u679c\u4f60\u6ca1\u6709\u6307\u5b9a<code style=\"color: #2c3e50;\">status<\/code>\uff0cstatus code\u9ed8\u8ba4\u4e3a&#8221;302 Found&#8221;\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">redirect<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/foo\/bar'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">redirect<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'http:\/\/example.com'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">redirect<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">301<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'http:\/\/example.com'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">redirect<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'..\/login'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"vln4\">\u91cd\u5b9a\u5411\u4e5f\u53ef\u4ee5\u662f\u5b8c\u6574\u7684URL\uff0c\u6765\u91cd\u5b9a\u5411\u5230\u4e0d\u540c\u7684\u7ad9\u70b9\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">redirect<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'http:\/\/google.com'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"epup\">\u91cd\u5b9a\u5411\u4e5f\u53ef\u4ee5\u76f8\u5bf9\u4e8e\u4e3b\u673a\u7684\u6839\u8def\u5f84\u3002\u6bd4\u5982\uff0c\u5982\u679c\u7a0b\u5e8f\u7684\u8def\u5f84\u4e3a<code style=\"color: #2c3e50;\">http:\/\/example.com\/admin\/post\/new<\/code>\uff0c\u90a3\u4e48\u4e0b\u9762\u5c06\u91cd\u5b9a\u5411\u5230<code style=\"color: #2c3e50;\">http:\/\/example.com\/admim<\/code>:<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">redirect<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/admin'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"ogq3\">\u91cd\u5b9a\u5411\u4e5f\u53ef\u4ee5\u76f8\u5bf9\u4e8e\u5f53\u524d\u7684URL\u3002\u6bd4\u5982\uff0c\u6765\u4e4b\u4e8e<code style=\"color: #2c3e50;\">http:\/\/example.com\/blog\/admin\/<\/code>(\u6ce8\u610f\u7ed3\u5c3e\u7684<code style=\"color: #2c3e50;\">\/<\/code>)\uff0c\u4e0b\u9762\u5c06\u91cd\u5b9a\u5411\u5230<code style=\"color: #2c3e50;\">http:\/\/example.com\/blog\/admin\/post\/new<\/code>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">redirect<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'post\/new'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"jx1t\">\u5982\u679c\u6765\u81f3\u4e8e<code style=\"color: #2c3e50;\">http:\/\/example.com\/blog\/admin<\/code>\uff08\u6ca1\u6709\u5c3e\u90e8<code style=\"color: #2c3e50;\">\/<\/code>\uff09\uff0c\u91cd\u5b9a\u5411<code style=\"color: #2c3e50;\">post\/new<\/code>\uff0c\u5c06\u91cd\u5b9a\u5411\u5230<code style=\"color: #2c3e50;\">http:\/\/example.com\/blog\/post\/new<\/code>\u3002\u5982\u679c\u4f60\u89c9\u5f97\u4e0a\u9762\u5f88\u6df7\u4e71\uff0c\u53ef\u4ee5\u628a\u8def\u5f84\u6bb5\u8ba4\u4e3a\u76ee\u5f55(\u6709&#8217;\/&#8217;)\u6216\u8005\u6587\u4ef6\uff0c\u8fd9\u6837\u662f\u53ef\u4ee5\u7684\u3002\u76f8\u5bf9\u8def\u5f84\u7684\u91cd\u5b9a\u5411\u4e5f\u662f\u53ef\u4ee5\u7684\u3002\u5982\u679c\u4f60\u5f53\u524d\u7684\u8def\u5f84\u4e3a<code style=\"color: #2c3e50;\">http:\/\/example.com\/admin\/post\/new<\/code>\uff0c\u4e0b\u9762\u7684\u64cd\u4f5c\u5c06\u91cd\u5b9a\u5411\u5230<code style=\"color: #2c3e50;\">http:\/\/example.com\/admin\/post<\/code>\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">redirect<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'..'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"law4\"><code style=\"color: #2c3e50;\">back<\/code>\u5c06\u91cd\u5b9a\u5411\u8bf7\u6c42\u5230<a style=\"color: #0088cc;\" href=\"http:\/\/en.wikipedia.org\/wiki\/HTTP_referer\" target=\"_blank\">referer<\/a>\uff0c\u5f53\u6ca1\u6709<code style=\"color: #2c3e50;\">referer<\/code>\u7684\u65f6\u5019\uff0c\u9ed8\u8ba4\u4e3a<code style=\"color: #2c3e50;\">\/<\/code>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">redirect<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'back'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"resrenderview-locals-callback\" style=\"color: #2c3e50;\" data-anchor-id=\"vb68\">res.render(view [, locals] [, callback])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"syv7\">\u6e32\u67d3\u4e00\u4e2a\u89c6\u56fe\uff0c\u7136\u540e\u5c06\u6e32\u67d3\u5f97\u5230\u7684HTML\u6587\u6863\u53d1\u9001\u7ed9\u5ba2\u6237\u7aef\u3002\u53ef\u9009\u7684\u53c2\u6570\u4e3a:<\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li style=\"color: #2c3e50;\" data-anchor-id=\"uj63\"><code style=\"color: #2c3e50;\">locals<\/code>\uff0c\u5b9a\u4e49\u4e86\u89c6\u56fe\u672c\u5730\u53c2\u6570\u5c5e\u6027\u7684\u4e00\u4e2a\u5bf9\u8c61\u3002<\/li>\n<li style=\"color: #2c3e50;\" data-anchor-id=\"qata\"><code style=\"color: #2c3e50;\">callback<\/code>\uff0c\u4e00\u4e2a\u56de\u8c03\u65b9\u6cd5\u3002\u5982\u679c\u63d0\u4f9b\u4e86\u8fd9\u4e2a\u53c2\u6570\uff0c<code style=\"color: #2c3e50;\">render<\/code>\u65b9\u6cd5\u5c06\u8fd4\u56de\u9519\u8bef\u548c\u6e32\u67d3\u4e4b\u540e\u7684\u6a21\u677f\uff0c\u5e76\u4e14\u4e0d\u81ea\u52a8\u53d1\u9001\u54cd\u5e94\u3002\u5f53\u6709\u9519\u8bef\u53d1\u751f\u65f6\uff0c\u53ef\u4ee5\u5728\u8fd9\u4e2a\u56de\u8c03\u5185\u90e8\uff0c\u8c03\u7528<code style=\"color: #2c3e50;\">next(err)<\/code>\u65b9\u6cd5\u3002<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<blockquote class=\"white-blockquote\" style=\"color: #2c3e50;\" data-anchor-id=\"uto5\">\n<p style=\"font-weight: 300;\">\u672c\u5730\u53d8\u91cf\u7f13\u5b58\u4f7f\u80fd\u89c6\u56fe\u7f13\u5b58\u3002\u5728\u5f00\u53d1\u73af\u5883\u4e2d\u7f13\u5b58\u89c6\u56fe\uff0c\u9700\u8981\u624b\u52a8\u8bbe\u7f6e\u4e3atrue\uff1b\u89c6\u56fe\u7f13\u5b58\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u9ed8\u8ba4\u5f00\u542f\u3002<\/p>\n<\/blockquote>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ send the rendered view to the client<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">render<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'index'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ if a callback is specified, the render HTML string has to be sent explicitly<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">render<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'index'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">err<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> html<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">html<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ pass a local variable to the view<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">render<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'user'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><span class=\"pln\" style=\"color: #000000;\">name<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'Tobi'<\/span><span class=\"pun\" style=\"color: #666600;\">},<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">err<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> html<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ ...<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"ressendbody\" style=\"color: #2c3e50;\" data-anchor-id=\"mcpp\">res.send([body])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"0clc\">\u53d1\u9001HTTP\u54cd\u5e94\u3002<br \/>\n<code style=\"color: #2c3e50;\">body<\/code>\u53c2\u6570\u53ef\u4ee5\u662f\u4e00\u4e2a<code style=\"color: #2c3e50;\">Buffer<\/code>\u5bf9\u8c61\uff0c\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u4e00\u4e2a\u5bf9\u8c61\uff0c\u6216\u8005\u4e00\u4e2a\u6570\u7ec4\u3002\u6bd4\u5982\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">new<\/span><span class=\"typ\" style=\"color: #660066;\">Buffer<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'whoop'<\/span><span class=\"pun\" style=\"color: #666600;\">));<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">({<\/span><span class=\"pln\" style=\"color: #000000;\">some<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'json'<\/span><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'&lt;p&gt;some html&lt;\/p&gt;'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">status<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">404<\/span><span class=\"pun\" style=\"color: #666600;\">).<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Sorry, we cannot find that!'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">status<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">500<\/span><span class=\"pun\" style=\"color: #666600;\">).<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">({<\/span><span class=\"pln\" style=\"color: #000000;\"> error<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'something blew up'<\/span><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"xscf\">\u5bf9\u4e8e\u4e00\u822c\u7684\u975e\u6d41\u8bf7\u6c42\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u6267\u884c\u8bb8\u591a\u6709\u7528\u7684\u7684\u4efb\u52a1\uff1a\u6bd4\u5982\uff0c\u5b83\u81ea\u52a8\u7ed9<code style=\"color: #2c3e50;\">Content-Length<\/code>HTTP\u54cd\u5e94\u5934\u8d4b\u503c(\u9664\u975e\u5148\u524d\u5b9a\u4e49)\uff0c\u4e5f\u652f\u6301\u81ea\u52a8\u7684HEAD\u548cHTTP\u7f13\u5b58\u66f4\u65b0\u3002<br \/>\n\u5f53\u53c2\u6570\u662f\u4e00\u4e2a<code style=\"color: #2c3e50;\">Buffer<\/code>\u5bf9\u8c61\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u8bbe\u7f6e<code style=\"color: #2c3e50;\">Content-Type<\/code>\u54cd\u5e94\u5934\u4e3a<code style=\"color: #2c3e50;\">application\/octet-stream<\/code>\uff0c\u9664\u975e\u4e8b\u5148\u63d0\u4f9b\uff0c\u5982\u4e0b\u6240\u793a:<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">set<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Content-Type'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'text\/html'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">new<\/span><span class=\"typ\" style=\"color: #660066;\">Buffer<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'&lt;p&gt;some html&lt;\/p&gt;'<\/span><span class=\"pun\" style=\"color: #666600;\">));<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"uqvc\">\u5f53\u53c2\u6570\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u8bbe\u7f6e<code style=\"color: #2c3e50;\">Content-Type<\/code>\u54cd\u5e94\u5934\u4e3a<code style=\"color: #2c3e50;\">text\/html<\/code>\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'&lt;p&gt;some html&lt;\/p&gt;'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"2k9q\">\u5f53\u53c2\u6570\u662f\u4e00\u4e2a\u5bf9\u8c61\u6216\u8005\u6570\u7ec4\uff0cExpress\u4f7f\u7528JSON\u683c\u5f0f\u6765\u8868\u793a\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">({<\/span><span class=\"pln\" style=\"color: #000000;\">user<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'tobi'<\/span><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">([<\/span><span class=\"lit\" style=\"color: #006666;\">1<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"lit\" style=\"color: #006666;\">2<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"lit\" style=\"color: #006666;\">3<\/span><span class=\"pun\" style=\"color: #666600;\">]);<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"ressendfilepath-options-fn\" style=\"color: #2c3e50;\" data-anchor-id=\"4sox\">res.sendFile(path [, options] [, fn])<\/h4>\n<blockquote class=\"white-blockquote\" style=\"color: #2c3e50;\" data-anchor-id=\"09cz\">\n<p style=\"font-weight: 300;\"><code style=\"color: #2c3e50;\">res.sendFile()<\/code>\u4ece<code style=\"color: #2c3e50;\">Express v4.8.0<\/code>\u5f00\u59cb\u652f\u6301\u3002<\/p>\n<\/blockquote>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"imp2\">\u4f20\u8f93<code style=\"color: #2c3e50;\">path<\/code>\u6307\u5b9a\u7684\u6587\u4ef6\u3002\u6839\u636e\u6587\u4ef6\u7684\u6269\u5c55\u540d\u8bbe\u7f6e<code style=\"color: #2c3e50;\">Content-Type<\/code>HTTP\u5934\u90e8\u3002\u9664\u975e\u5728<code style=\"color: #2c3e50;\">options<\/code>\u4e2d\u6709\u5173\u4e8e<code style=\"color: #2c3e50;\">root<\/code>\u7684\u8bbe\u7f6e\uff0c<code style=\"color: #2c3e50;\">path<\/code>\u4e00\u5b9a\u662f\u5173\u4e8e\u6587\u4ef6\u7684\u7edd\u5bf9\u8def\u5f84\u3002<br \/>\n\u4e0b\u9762\u7684\u8868\u63d0\u4f9b\u4e86<code style=\"color: #2c3e50;\">options<\/code>\u53c2\u6570\u7684\u7ec6\u8282:<\/p>\n<table class=\"table table-striped-white table-bordered\" style=\"color: #2c3e50;\" data-anchor-id=\"oijo\">\n<thead>\n<tr>\n<th style=\"font-weight: bold;\">\u5c5e\u6027<\/th>\n<th style=\"font-weight: bold;\">\u63cf\u8ff0<\/th>\n<th style=\"font-weight: bold;\">\u9ed8\u8ba4\u503c<\/th>\n<th style=\"font-weight: bold;\">\u53ef\u7528\u7248\u672c<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>maxAge<\/td>\n<td>\u8bbe\u7f6e<code style=\"color: #2c3e50;\">Cache-Control<\/code>\u7684<code style=\"color: #2c3e50;\">max-age<\/code>\u5c5e\u6027\uff0c\u683c\u5f0f\u4e3a\u6beb\u79d2\u6570\uff0c\u6216\u8005\u662f<a style=\"color: #0088cc;\" href=\"https:\/\/www.npmjs.org\/package\/ms\" target=\"_blank\">ms format<\/a>\u7684\u4e00\u4e32\u5b57\u7b26\u4e32<\/td>\n<td>0<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>root<\/td>\n<td>\u76f8\u5bf9\u6587\u4ef6\u540d\u7684\u6839\u76ee\u5f55<\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>lastModified<\/td>\n<td>\u8bbe\u7f6e<code style=\"color: #2c3e50;\">Last-Modified<\/code>\u5934\u90e8\u4e3a\u6b64\u6587\u4ef6\u5728\u7cfb\u7edf\u4e2d\u7684\u6700\u540e\u4e00\u6b21\u4fee\u6539\u65f6\u95f4\u3002\u8bbe\u7f6e<code style=\"color: #2c3e50;\">false<\/code>\u6765\u7981\u7528\u5b83<\/td>\n<td>Enable<\/td>\n<td>4.9.0+<\/td>\n<\/tr>\n<tr>\n<td>headers<\/td>\n<td>\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5305\u542b\u4e86\u6587\u4ef6\u6240\u5728\u7684sever\u7684HTTP\u5934\u90e8\u3002(\u4e0d\u77e5\u9053\u600e\u4e48\u7ffb\u8bd1\u4e86)<\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>dotfiles<\/td>\n<td>\u662f\u5426\u652f\u6301\u70b9\u5f00\u5934\u6587\u4ef6\u540d\u7684\u9009\u9879\u3002\u53ef\u9009\u7684\u503c&#8221;allow&#8221;,&#8221;deny&#8221;,&#8221;ignore&#8221;<\/td>\n<td>&#8220;ignore&#8221;<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"n8bm\">\u5f53\u4f20\u8f93\u5b8c\u6210\u6216\u8005\u53d1\u751f\u4e86\u4ec0\u4e48\u9519\u8bef\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u8c03\u7528<code style=\"color: #2c3e50;\">fn<\/code>\u56de\u8c03\u65b9\u6cd5\u3002\u5982\u679c\u8fd9\u4e2a\u56de\u8c03\u53c2\u6570\u6307\u5b9a\u4e86\u548c\u4e00\u4e2a\u9519\u8bef\u53d1\u751f\uff0c\u56de\u8c03\u65b9\u6cd5\u5fc5\u987b\u660e\u786e\u5730\u901a\u8fc7\u7ed3\u675f\u8bf7\u6c42-\u54cd\u5e94\u5faa\u73af\u6216\u8005\u4f20\u9012\u63a7\u5236\u5230\u4e0b\u4e2a\u8def\u7531\u6765\u5904\u7406\u54cd\u5e94\u8fc7\u7a0b\u3002<br \/>\n\u4e0b\u9762\u662f\u4f7f\u7528\u4e86\u6240\u6709\u53c2\u6570\u7684\u4f7f\u7528<code style=\"color: #2c3e50;\">res.sendFile()<\/code>\u7684\u4f8b\u5b50\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/file\/:name'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> options <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> root<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"pln\" style=\"color: #000000;\">__dirname <\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"str\" style=\"color: #008800;\">'\/public'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> dotfile<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'deny'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> headers<\/span><span class=\"pun\" style=\"color: #666600;\">:{<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"str\" style=\"color: #008800;\">'x-timestamp'<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"typ\" style=\"color: #660066;\">Date<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">now<\/span><span class=\"pun\" style=\"color: #666600;\">(),<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"str\" style=\"color: #008800;\">'x-sent'<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"kwd\" style=\"color: #000088;\">true<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">};<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> fileName <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">params<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">name<\/span><span class=\"pun\" style=\"color: #666600;\">;<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">sendFile<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">fileName<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> options<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">err<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">if<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">err<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">err<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">status<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">err<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">status<\/span><span class=\"pun\" style=\"color: #666600;\">).<\/span><span class=\"pln\" style=\"color: #000000;\">end<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">else<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'sent'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> fileName<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"dxzg\"><code style=\"color: #2c3e50;\">res.sendFile<\/code>\u63d0\u4f9b\u4e86\u6587\u4ef6\u670d\u52a1\u7684\u7ec6\u7c92\u5ea6\u652f\u6301\uff0c\u5982\u4e0b\u4f8b\u5b50\u8bf4\u660e\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/user\/:uid\/photos\/:file'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> uid <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">params<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">uid<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> file <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">params<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">file<\/span><span class=\"pun\" style=\"color: #666600;\">;<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">user<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">mayViewFilesFrom<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">uid<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">yes<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">if<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">yes<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">sendFile<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/upload\/'<\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"pln\" style=\"color: #000000;\"> uid <\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"str\" style=\"color: #008800;\">'\/'<\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"pln\" style=\"color: #000000;\"> file<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">else<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">status<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">403<\/span><span class=\"pun\" style=\"color: #666600;\">).<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Sorry! you cant see that.'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">})<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"7xk5\">\u83b7\u53d6\u66f4\u591a\u4fe1\u606f\uff0c\u6216\u8005\u4f60\u6709\u95ee\u9898\u6216\u8005\u5173\u6ce8\uff0c\u53ef\u4ee5\u67e5\u9605<a style=\"color: #0088cc;\" href=\"https:\/\/github.com\/pillarjs\/send?_ga=1.256986891.1201680737.1446005628\" target=\"_blank\">send<\/a>\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"ressendstatusstatuscode\" style=\"color: #2c3e50;\" data-anchor-id=\"8x87\">res.sendStatus(statusCode)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"w7ok\">\u8bbe\u7f6e\u54cd\u5e94\u5bf9\u8c61\u7684<code style=\"color: #2c3e50;\">HTTP status code<\/code>\u4e3a<code style=\"color: #2c3e50;\">statusCode<\/code>\u5e76\u4e14\u53d1\u9001<code style=\"color: #2c3e50;\">statusCode<\/code>\u7684\u76f8\u5e94\u7684\u5b57\u7b26\u4e32\u5f62\u5f0f\u4f5c\u4e3a\u54cd\u5e94\u7684Body\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">sendStatus<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">200<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ equivalent to res.status(200).send('OK');<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">sendStatus<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">403<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ equivalent to res.status(403).send('Forbidden');<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">sendStatus<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">404<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ equivalent to res.status(404).send('Not Found');<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">sendStatus<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">500<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ equivalent to res.status(500).send('Internal Server Error')<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"h2oz\">\u5982\u679c\u4e00\u4e2a\u4e0d\u652f\u6301\u7684\u72b6\u6001\u88ab\u6307\u5b9a\uff0c\u8fd9\u4e2aHTTP status\u4f9d\u7136\u88ab\u8bbe\u7f6e\u4e3a<code style=\"color: #2c3e50;\">statusCode<\/code>\u5e76\u4e14\u7528\u8fd9\u4e2acode\u7684\u5b57\u7b26\u4e32\u4f5c\u4e3aBody\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">sendStatus<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">2000<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ equivalent to res.status(2000).send('2000');<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"j2y0\"><a style=\"color: #0088cc;\" href=\"http:\/\/en.wikipedia.org\/wiki\/List_of_HTTP_status_codes\" target=\"_blank\">More about HTTP Status Codes<\/a><\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"ressetfield-value\" style=\"color: #2c3e50;\" data-anchor-id=\"tt7v\">res.set(field [, value])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"7pgs\">\u8bbe\u7f6e\u54cd\u5e94\u5bf9\u8c61\u7684HTTP\u5934\u90e8<code style=\"color: #2c3e50;\">field<\/code>\u4e3a<code style=\"color: #2c3e50;\">value<\/code>\u3002\u4e3a\u4e86\u4e00\u6b21\u8bbe\u7f6e\u591a\u4e2a\u503c\uff0c\u90a3\u4e48\u53ef\u4ee5\u4f20\u9012\u4e00\u4e2a\u5bf9\u8c61\u4e3a\u53c2\u6570\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">set<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Content-Type'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"str\" style=\"color: #008800;\">'text\/plain'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">set<\/span><span class=\"pun\" style=\"color: #666600;\">({<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"str\" style=\"color: #008800;\">'Content-Type'<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'text\/plain'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"str\" style=\"color: #008800;\">'Content-Length'<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'123'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"str\" style=\"color: #008800;\">'ETag'<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">'123456'<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">})<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"5m41\">\u5176\u548c<code style=\"color: #2c3e50;\">res.header(field [,value])<\/code>\u6548\u679c\u4e00\u81f4\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"resstatuscode\" style=\"color: #2c3e50;\" data-anchor-id=\"s30p\">res.status(code)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"m5cw\">\u4f7f\u7528\u8fd9\u4e2a\u65b9\u6cd5\u6765\u8bbe\u7f6e\u54cd\u5e94\u5bf9\u8c61\u7684HTTP status\u3002\u5176\u662fNode\u4e2d<a style=\"color: #0088cc;\" href=\"http:\/\/nodejs.org\/api\/http.html#http_response_statuscode\" target=\"_blank\">response.statusCode<\/a>\u7684\u4e00\u4e2a\u8fde\u8d2f\u6027\u7684\u522b\u540d\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">status<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">403<\/span><span class=\"pun\" style=\"color: #666600;\">).<\/span><span class=\"pln\" style=\"color: #000000;\">end<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">status<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">400<\/span><span class=\"pun\" style=\"color: #666600;\">).<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Bad Request'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">status<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">404<\/span><span class=\"pun\" style=\"color: #666600;\">).<\/span><span class=\"pln\" style=\"color: #000000;\">sendFile<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/absolute\/path\/to\/404.png'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"restypetype\" style=\"color: #2c3e50;\" data-anchor-id=\"mdix\">res.type(type)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"vcto\">\u8bbe\u7f6e<code style=\"color: #2c3e50;\">Content-Type<\/code>HTTP\u5934\u90e8\u4e3aMIME type\uff0c\u5982\u679c\u8fd9\u4e2a\u6307\u5b9a\u7684type\u80fd\u591f\u88ab<a style=\"color: #0088cc;\" href=\"https:\/\/github.com\/broofa\/node-mime?_ga=1.67301009.1201680737.1446005628#mimelookuppath\" target=\"_blank\">mime.lookup<\/a>\u786e\u5b9a\u3002\u5982\u679c<code style=\"color: #2c3e50;\">type<\/code>\u5305\u542b<code style=\"color: #2c3e50;\">\/<\/code>\u5b57\u7b26\uff0c\u90a3\u4e48\u8bbe\u7f6e<code style=\"color: #2c3e50;\">Content-Type<\/code>\u4e3a<code style=\"color: #2c3e50;\">type<\/code>(\u6211\u5df2\u7ecf\u6655\u4e86)\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">type<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'.html'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; 'text\/html'<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">type<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'html'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; 'text\/html'<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">type<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'json'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; 'application\/json'<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">type<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'application\/json'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; 'application\/json'<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">type<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'png'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><span class=\"com\" style=\"color: #880000;\">\/\/ =&gt; image\/png:<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"resvaryfield\" style=\"color: #2c3e50;\" data-anchor-id=\"8tzf\">res.vary(field)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"mx6h\">\u8bbe\u7f6e<code style=\"color: #2c3e50;\">Vary<\/code>\u54cd\u5e94\u5934\u4e3a<code style=\"color: #2c3e50;\">field<\/code>\uff0c\u5982\u679c\u5df2\u7ecf\u4e0d\u5728\u90a3\u91cc\u3002(\u4e0d\u61c2\u4ec0\u4e48\u610f\u601d)<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">vary<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'User-Agent'<\/span><span class=\"pun\" style=\"color: #666600;\">).<\/span><span class=\"pln\" style=\"color: #000000;\">render<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'docs'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h2 id=\"router\" style=\"color: #2c3e50;\" data-anchor-id=\"eydo\">Router<\/h2>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"yp1j\">\u4e00\u4e2a<code style=\"color: #2c3e50;\">router<\/code>\u5bf9\u8c61\u662f\u4e00\u4e2a\u5355\u72ec\u7684\u5b9e\u4f8b\u5173\u4e8e\u4e2d\u95f4\u4ef6\u548c\u8def\u7531\u3002\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u5176\u662f\u4e00\u4e2a&#8221;mini-application&#8221;\uff08\u8ff7\u4f60\u7a0b\u5e8f\uff09\uff0c\u5176\u5177\u6709\u64cd\u4f5c\u4e2d\u95f4\u4ef6\u548c\u8def\u7531\u65b9\u6cd5\u7684\u80fd\u529b\u3002\u6bcf\u4e2a<code style=\"color: #2c3e50;\">Express<\/code>\u7a0b\u5e8f\u6709\u4e00\u4e2a\u5185\u5efa\u7684app\u8def\u7531\u3002<br \/>\n\u8def\u7531\u81ea\u8eab\u8868\u73b0\u4e3a\u4e00\u4e2a\u4e2d\u95f4\u4ef6\uff0c\u6240\u4ee5\u4f60\u53ef\u4ee5\u4f7f\u7528\u5b83\u4f5c\u4e3a<code style=\"color: #2c3e50;\">app.use()<\/code>\u65b9\u6cd5\u7684\u4e00\u4e2a\u53c2\u6570\u6216\u8005\u4f5c\u4e3a\u53e6\u4e00\u4e2a\u8def\u7531\u7684<code style=\"color: #2c3e50;\">use()<\/code>\u7684\u53c2\u6570\u3002<br \/>\n\u9876\u5c42\u7684<code style=\"color: #2c3e50;\">express<\/code>\u5bf9\u8c61\u6709\u4e00\u4e2a<code style=\"color: #2c3e50;\">Router()<\/code>\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code style=\"color: #2c3e50;\">Router()<\/code>\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u7684<code style=\"color: #2c3e50;\">router<\/code>\u5bf9\u8c61\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"routeroptions\" style=\"color: #2c3e50;\" data-anchor-id=\"42cr\">Router([options])<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"ezsk\">\u5982\u4e0b\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u8def\u7531\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> router <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> express<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"typ\" style=\"color: #660066;\">Router<\/span><span class=\"pun\" style=\"color: #666600;\">([<\/span><span class=\"pln\" style=\"color: #000000;\">options<\/span><span class=\"pun\" style=\"color: #666600;\">]);<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"3bv5\"><code style=\"color: #2c3e50;\">options<\/code>\u53c2\u6570\u53ef\u4ee5\u6307\u5b9a\u8def\u7531\u7684\u884c\u4e3a\uff0c\u5176\u6709\u4e0b\u5217\u9009\u62e9\uff1a<\/p>\n<table class=\"table table-striped-white table-bordered\" style=\"color: #2c3e50;\" data-anchor-id=\"vacv\">\n<thead>\n<tr>\n<th style=\"font-weight: bold;\">\u5c5e\u6027<\/th>\n<th style=\"font-weight: bold;\">\u63cf\u8ff0<\/th>\n<th style=\"font-weight: bold;\">\u9ed8\u8ba4\u503c<\/th>\n<th style=\"font-weight: bold;\">\u53ef\u7528\u6027<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>caseSensitive<\/td>\n<td>\u662f\u5426\u533a\u5206\u5927\u5c0f\u5199<\/td>\n<td>\u9ed8\u8ba4\u4e0d\u542f\u7528\u3002\u5bf9\u5f85<code style=\"color: #2c3e50;\">\/Foo<\/code>\u548c<code style=\"color: #2c3e50;\">\/foo<\/code>\u4e00\u6837\u3002<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>mergeParams<\/td>\n<td>\u4fdd\u5b58\u7236\u8def\u7531\u7684<code style=\"color: #2c3e50;\">res.params<\/code>\u3002\u5982\u679c\u7236\u8def\u7531\u53c2\u6570\u548c\u5b50\u8def\u7531\u53c2\u6570\u51b2\u7a81\uff0c\u5b50\u8def\u7531\u53c2\u6570\u4f18\u5148\u3002<\/td>\n<td>false<\/td>\n<td>4.5.0+<\/td>\n<\/tr>\n<tr>\n<td>strict<\/td>\n<td>\u4f7f\u80fd\u4e25\u683c\u8def\u7531\u3002<\/td>\n<td>\u9ed8\u8ba4\u4e0d\u542f\u7528\uff0c<code style=\"color: #2c3e50;\">\/foo<\/code>\u548c<code style=\"color: #2c3e50;\">\/foo\/<\/code>\u88ab\u8def\u7531\u4e00\u6837\u5bf9\u5f85\u5904\u7406<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"8b07\">\u4f60\u53ef\u4ee5\u5c06<code style=\"color: #2c3e50;\">router<\/code>\u5f53\u4f5c\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u5728\u5176\u4e0a\u6dfb\u52a0\u4e2d\u95f4\u4ef6\u548cHTTP\u8def\u7531\u65b9\u6cd5(\u4f8b\u5982<code style=\"color: #2c3e50;\">get<\/code>\uff0c<code style=\"color: #2c3e50;\">put<\/code>\uff0c<code style=\"color: #2c3e50;\">post<\/code>\u7b49\u7b49)\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ invoked for any requests passed to this router<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ .. some logic here .. like any other middleware<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ will handle any request that ends in \/events<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ depends on where the router is \"use()'d\"<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/events'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ ..<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"v4js\">\u4f60\u53ef\u4ee5\u5728\u4e00\u4e2a\u7279\u522b\u7684\u6839URL\u4e0a\u6302\u8f7d\u4e00\u4e2a\u8def\u7531\uff0c\u8fd9\u6837\u4f60\u5c31\u4ee5\u5c06\u4f60\u7684\u5404\u4e2a\u8def\u7531\u653e\u5230\u4e0d\u540c\u7684\u6587\u4ef6\u4e2d\u6216\u8005\u751a\u81f3\u662fmini\u7684\u7a0b\u5e8f\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ only requests to \/calendar\/* will be sent to our \"router\"<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/calendar'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> router<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h3 id=\"methods-4\" style=\"color: #2c3e50;\" data-anchor-id=\"598w\">Methods<\/h3>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"routerallpath-callback-callback\" style=\"color: #2c3e50;\" data-anchor-id=\"8ohl\">router.all(path, [callback, &#8230;] callback)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"sr8z\">\u8fd9\u4e2a\u65b9\u6cd5\u548c<code style=\"color: #2c3e50;\">router.METHOD()<\/code>\u65b9\u6cd5\u4e00\u6837\uff0c\u9664\u4e86\u8fd9\u4e2a\u65b9\u6cd5\u4f1a\u5339\u914d\u6240\u6709\u7684HTTP\u52a8\u4f5c\u3002<br \/>\n\u8fd9\u4e2a\u65b9\u6cd5\u5bf9\u60f3\u6620\u5c04\u5168\u5c40\u7684\u903b\u8f91\u5904\u7406\u5230\u7279\u6b8a\u7684\u8def\u5f84\u524d\u7f00\u6216\u8005\u4efb\u610f\u5339\u914d\u662f\u5341\u5206\u6709\u7528\u7684\u3002\u6bd4\u5982\uff0c\u5982\u679c\u4f60\u653e\u7f6e\u4e0b\u9762\u6240\u793a\u7684\u8fd9\u4e2a\u8def\u7531\u5728\u5176\u4ed6\u8def\u7531\u7684\u524d\u9762\uff0c\u90a3\u4e48\u5176\u5c06\u8981\u6c42\u4ece\u8fd9\u4e2a\u70b9\u5f00\u59cb\u7684\u6240\u6709\u7684\u8def\u7531\u8fdb\u884c\u9a8c\u8bc1\u64cd\u4f5c\u548c\u81ea\u52a8\u52a0\u8f7d\u7528\u6237\u4fe1\u606f\u3002\u8bb0\u4f4f\uff0c\u8fd9\u4e9b\u5168\u5c40\u7684\u903b\u8f91\u64cd\u4f5c\uff0c\u4e0d\u9700\u8981\u7ed3\u675f\u8bf7\u6c42\u54cd\u5e94\u5468\u671f\uff1a<code style=\"color: #2c3e50;\">loaduser<\/code>\u53ef\u4ee5\u6267\u884c\u4e00\u4e2a\u4efb\u52a1\uff0c\u7136\u540e\u8c03\u7528<code style=\"color: #2c3e50;\">next()<\/code>\u6765\u5c06\u6267\u884c\u6d41\u7a0b\u79fb\u4ea4\u5230\u968f\u540e\u7684\u8def\u7531\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">all<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'*'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> requireAuthentication<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> loadUser<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"tlik\">\u76f8\u7b49\u7684\u5f62\u5f0f:<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">all<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'*'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> requireAuthentication<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">all<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'*'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> loadUser<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"jqgb\">\u8fd9\u662f\u4e00\u4e2a\u767d\u540d\u5355\u5168\u5c40\u529f\u80fd\u7684\u4f8b\u5b50\u3002\u8fd9\u4e2a\u4f8b\u5b50\u5f88\u50cf\u524d\u9762\u7684\uff0c\u4e0d\u8fc7\u5176\u4ec5\u4ec5\u4f5c\u7528\u4e8e\u4ee5<code style=\"color: #2c3e50;\">\/api<\/code>\u5f00\u5934\u7684\u8def\u5f84:<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">all<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/api\/*'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> requireAuthentication<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"routermethodpath-callback-callback\" style=\"color: #2c3e50;\" data-anchor-id=\"o0p9\">router.METHOD(path, [callback, &#8230;] callback)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"vnsm\"><code style=\"color: #2c3e50;\">router.METHOD()<\/code>\u65b9\u6cd5\u63d0\u4f9b\u4e86\u8def\u7531\u65b9\u6cd5\u5728<code style=\"color: #2c3e50;\">Express<\/code>\u4e2d\uff0c\u8fd9\u91cc\u7684<code style=\"color: #2c3e50;\">METHOD<\/code>\u662fHTTP\u65b9\u6cd5\u4e2d\u7684\u4e00\u4e2a\uff0c\u6bd4\u5982<code style=\"color: #2c3e50;\">GET<\/code>\uff0c<code style=\"color: #2c3e50;\">PUT<\/code>\uff0c<code style=\"color: #2c3e50;\">POST<\/code>\u7b49\u7b49\uff0c\u4f46<code style=\"color: #2c3e50;\">router<\/code>\u4e2d\u7684METHOD\u662f\u5c0f\u5199\u7684\u3002\u6240\u4ee5\uff0c\u5b9e\u9645\u7684\u65b9\u6cd5\u662f<code style=\"color: #2c3e50;\">router.get()<\/code>\uff0c<code style=\"color: #2c3e50;\">router.put()<\/code>\uff0c<code style=\"color: #2c3e50;\">router.post()<\/code>\u7b49\u7b49\u3002<br \/>\n\u4f60\u53ef\u4ee5\u63d0\u4f9b\u591a\u4e2a\u56de\u8c03\u51fd\u6570\uff0c\u5b83\u4eec\u7684\u884c\u4e3a\u548c\u4e2d\u95f4\u4ef6\u4e00\u6837\uff0c\u9664\u4e86\u8fd9\u4e9b\u56de\u8c03\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528<code style=\"color: #2c3e50;\">next('router')<\/code>\u6765\u7ed5\u8fc7\u5269\u4f59\u7684\u8def\u7531\u56de\u8c03\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u673a\u5236\u6765\u4e3a\u4e00\u4e2a\u8def\u7531\u8bbe\u7f6e\u4e00\u4e9b\u524d\u63d0\u6761\u4ef6\uff0c\u5982\u679c\u8bf7\u6c42\u6ca1\u6709\u6ee1\u8db3\u5f53\u524d\u8def\u7531\u7684\u5904\u7406\u6761\u4ef6\uff0c\u90a3\u4e48\u4f20\u9012\u63a7\u5236\u5230\u968f\u540e\u7684\u8def\u7531\u3002<br \/>\n\u4e0b\u9762\u7684\u7247\u6bb5\u53ef\u80fd\u8bf4\u660e\u4e86\u6700\u7b80\u5355\u7684\u8def\u7531\u5b9a\u4e49\u3002Experss\u8f6c\u6362path\u5b57\u7b26\u4e32\u4e3a\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u7528\u4e8e\u5185\u90e8\u5339\u914d\u4f20\u5165\u7684\u8bf7\u6c42\u3002\u5728\u5339\u914d\u7684\u65f6\u5019\uff0c\u662f\u4e0d\u8003\u8651<code style=\"color: #2c3e50;\">Query strings<\/code>\uff0c\u4f8b\u5982\uff0c&#8221;GET \/&#8221;\u5c06\u5339\u914d\u4e0b\u9762\u7684\u8def\u7531\uff0c&#8221;GET \/?name=tobi&#8221;\u4e5f\u662f\u4e00\u6837\u7684\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Hello World'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"zgcj\">\u5982\u679c\u4f60\u5bf9\u5339\u914d\u7684path\u6709\u7279\u6b8a\u7684\u9650\u5236\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u4f8b\u5982\uff0c\u4e0b\u9762\u7684\u53ef\u4ee5\u5339\u914d&#8221;GET \/commits\/71dbb9c&#8221;\u548c&#8221;GET \/commits\/71bb92..4c084f9&#8243;\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">\/^\\\/commits\\\/(\\w+)(?:\\.\\.(\\w+))?$\/<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> from <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">params<\/span><span class=\"pun\" style=\"color: #666600;\">[<\/span><span class=\"lit\" style=\"color: #006666;\">0<\/span><span class=\"pun\" style=\"color: #666600;\">];<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> to <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">params<\/span><span class=\"pun\" style=\"color: #666600;\">[<\/span><span class=\"lit\" style=\"color: #006666;\">1<\/span><span class=\"pun\" style=\"color: #666600;\">];<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'commit range '<\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"pln\" style=\"color: #000000;\"> from <\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"str\" style=\"color: #008800;\">'..'<\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"pln\" style=\"color: #000000;\"> to<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"routerparamname-callback\" style=\"color: #2c3e50;\" data-anchor-id=\"p9x1\">router.param(name, callback)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"7zcy\">\u7ed9\u8def\u7531\u53c2\u6570\u6dfb\u52a0\u56de\u8c03\u89e6\u53d1\u5668\uff0c\u8fd9\u91cc\u7684<code style=\"color: #2c3e50;\">name<\/code>\u662f\u53c2\u6570\u540d\uff0c<code style=\"color: #2c3e50;\">function<\/code>\u662f\u56de\u8c03\u65b9\u6cd5\u3002\u56de\u8c03\u65b9\u6cd5\u7684\u53c2\u6570\u6309\u5e8f\u662f\u8bf7\u6c42\u5bf9\u8c61\uff0c\u54cd\u5e94\u5bf9\u8c61\uff0c\u4e0b\u4e2a\u4e2d\u95f4\u4ef6\uff0c\u53c2\u6570\u503c\u548c\u53c2\u6570\u540d\u3002\u867d\u7136<code style=\"color: #2c3e50;\">name<\/code>\u5728\u6280\u672f\u4e0a\u662f\u53ef\u9009\u7684\uff0c\u4f46\u662f\u81eaExpress V4.11.0\u4e4b\u540e\u7248\u672c\u4e0d\u63a8\u8350\u4f7f\u7528(\u89c1\u4e0b\u9762)\u3002<\/p>\n<blockquote class=\"white-blockquote\" style=\"color: #2c3e50;\" data-anchor-id=\"br14\">\n<p style=\"font-weight: 300;\">\u4e0d\u50cf<code style=\"color: #2c3e50;\">app.param()<\/code>\uff0c<code style=\"color: #2c3e50;\">router.param()<\/code>\u4e0d\u63a5\u53d7\u4e00\u4e2a\u6570\u7ec4\u4f5c\u4e3a\u8def\u7531\u53c2\u6570\u3002<\/p>\n<\/blockquote>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"12nj\">\u4f8b\u5982\uff0c\u5f53<code style=\"color: #2c3e50;\">:user<\/code>\u51fa\u73b0\u5728\u8def\u7531\u8def\u5f84\u4e2d\uff0c\u4f60\u53ef\u4ee5\u6620\u5c04\u7528\u6237\u52a0\u8f7d\u7684\u903b\u8f91\u5904\u7406\u6765\u81ea\u52a8\u63d0\u4f9b<code style=\"color: #2c3e50;\">req.user<\/code>\u7ed9\u8fd9\u4e2a\u8def\u7531\uff0c\u6216\u8005\u5bf9\u8f93\u5165\u7684\u53c2\u6570\u8fdb\u884c\u9a8c\u8bc1\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">param<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'user'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> id<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"typ\" style=\"color: #660066;\">User<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">find<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">id<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">error<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> user<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">if<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">err<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">err<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">else<\/span><span class=\"kwd\" style=\"color: #000088;\">if<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">user<\/span><span class=\"pun\" style=\"color: #666600;\">){<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">user <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> user<\/span><span class=\"pun\" style=\"color: #666600;\">;<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><span class=\"kwd\" style=\"color: #000088;\">else<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">new<\/span><span class=\"typ\" style=\"color: #660066;\">Error<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'failed to load user'<\/span><span class=\"pun\" style=\"color: #666600;\">));<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"1y3w\">\u5bf9\u4e8e<code style=\"color: #2c3e50;\">Param<\/code>\u7684\u56de\u8c03\u5b9a\u4e49\u7684\u8def\u7531\u6765\u8bf4\uff0c\u4ed6\u4eec\u662f\u5c40\u90e8\u7684\u3002\u5b83\u4eec\u4e0d\u4f1a\u88ab\u6302\u8f7d\u7684app\u6216\u8005\u8def\u7531\u7ee7\u627f\u3002\u6240\u4ee5\uff0c\u5b9a\u4e49\u5728<code style=\"color: #2c3e50;\">router<\/code>\u4e0a\u7684<code style=\"color: #2c3e50;\">param<\/code>\u56de\u8c03\u53ea\u6709\u662f\u5728<code style=\"color: #2c3e50;\">router<\/code>\u4e0a\u7684\u8def\u7531\u5177\u6709\u8fd9\u4e2a\u8def\u7531\u53c2\u6570\u65f6\u624d\u8d77\u4f5c\u7528\u3002<br \/>\n\u5728\u5b9a\u4e49<code style=\"color: #2c3e50;\">param<\/code>\u7684\u8def\u7531\u4e0a\uff0c<code style=\"color: #2c3e50;\">param<\/code>\u56de\u8c03\u90fd\u662f\u7b2c\u4e00\u4e2a\u88ab\u8c03\u7528\u7684\uff0c\u5b83\u4eec\u5728\u4e00\u4e2a\u8bf7\u6c42-\u54cd\u5e94\u5faa\u73af\u4e2d\u90fd\u4f1a\u88ab\u8c03\u7528\u4e00\u6b21\u5e76\u4e14\u53ea\u6709\u4e00\u6b21\uff0c\u5373\u4f7f\u591a\u4e2a\u8def\u7531\u90fd\u5339\u914d\uff0c\u5982\u4e0b\u9762\u7684\u4f8b\u5b50\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">param<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'id'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> id<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'CALLED ONLY ONCE'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/user\/:id'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'although this matches'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/user\/:id'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'and this mathces too'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">end<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"pxwp\">\u5f53<code style=\"color: #2c3e50;\">GET \/user\/42<\/code>\uff0c\u5f97\u5230\u4e0b\u9762\u7684\u7ed3\u679c:<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-log\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> CALLED ONLY ONCE<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-log\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> although <\/span><span class=\"kwd\" style=\"color: #000088;\">this<\/span><span class=\"pln\" style=\"color: #000000;\"> matches<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-log\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">and<\/span><span class=\"kwd\" style=\"color: #000088;\">this<\/span><span class=\"pln\" style=\"color: #000000;\"> matches too<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"j5ho\">`<\/p>\n<blockquote class=\"white-blockquote\" style=\"color: #2c3e50;\" data-anchor-id=\"7awf\">\n<p style=\"font-weight: 300;\">\u4e0b\u9762\u7ae0\u8282\u63cf\u8ff0\u7684<code style=\"color: #2c3e50;\">router.param(callback)<\/code>\u5728v4.11.0\u4e4b\u540e\u88ab\u5f03\u7528\u3002<\/p>\n<\/blockquote>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"iguo\">\u901a\u8fc7\u53ea\u4f20\u9012\u4e00\u4e2a\u56de\u8c03\u53c2\u6570\u7ed9<code style=\"color: #2c3e50;\">router.param(name, callback)<\/code>\u65b9\u6cd5\uff0c<code style=\"color: #2c3e50;\">router.param(naem, callback)<\/code>\u65b9\u6cd5\u7684\u884c\u4e3a\u5c06\u88ab\u5b8c\u5168\u6539\u53d8\u3002\u8fd9\u4e2a\u56de\u8c03\u53c2\u6570\u662f\u5173\u4e8e<code style=\"color: #2c3e50;\">router.param(name, callback)<\/code>\u8be5\u5177\u6709\u600e\u6837\u7684\u884c\u4e3a\u7684\u4e00\u4e2a\u81ea\u5b9a\u4e49\u65b9\u6cd5\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u5fc5\u987b\u63a5\u53d7\u4e24\u4e2a\u53c2\u6570\u5e76\u4e14\u8fd4\u56de\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u3002<br \/>\n\u8fd9\u4e2a\u56de\u8c03\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u5c31\u662f\u9700\u8981\u6355\u83b7\u7684url\u7684\u53c2\u6570\u540d\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u53ef\u4ee5\u662f\u4efb\u4e00\u7684JavaScript\u5bf9\u8c61\uff0c\u5176\u53ef\u80fd\u5728\u5b9e\u73b0\u8fd4\u56de\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u65f6\u88ab\u4f7f\u7528\u3002<br \/>\n\u8fd9\u4e2a\u56de\u8c03\u65b9\u6cd5\u8fd4\u56de\u7684\u4e2d\u95f4\u4ef6\u51b3\u5b9a\u4e86\u5f53URL\u4e2d\u5305\u542b\u8fd9\u4e2a\u53c2\u6570\u65f6\u6240\u91c7\u53d6\u7684\u884c\u4e3a\u3002<br \/>\n\u5728\u4e0b\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c<code style=\"color: #2c3e50;\">router.param(name, callback)<\/code>\u53c2\u6570\u7b7e\u540d\u88ab\u4fee\u6539\u6210\u4e86<code style=\"color: #2c3e50;\">router.param(name, accessId)<\/code>\u3002\u66ff\u6362\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570\u540d\u548c\u56de\u8c03\uff0c<code style=\"color: #2c3e50;\">router.param()<\/code>\u73b0\u5728\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570\u540d\u548c\u4e00\u4e2a\u6570\u5b57\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> express <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> require<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'express'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> app <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> express<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> router <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> express<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"typ\" style=\"color: #660066;\">Router<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">param<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">param<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> option<\/span><span class=\"pun\" style=\"color: #666600;\">){<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">return<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> val<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">if<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">val <\/span><span class=\"pun\" style=\"color: #666600;\">==<\/span><span class=\"pln\" style=\"color: #000000;\"> option<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">else<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">sendStatus<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">403<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">param<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'id'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"lit\" style=\"color: #006666;\">1337<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/user\/:id'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Ok'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">listen<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">3000<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">()<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Ready'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"dhhy\">\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code style=\"color: #2c3e50;\">router.param(name. callback)<\/code>\u53c2\u6570\u7b7e\u540d\u4fdd\u6301\u548c\u539f\u6765\u4e00\u6837\uff0c\u4f46\u662f\u66ff\u6362\u6210\u4e86\u4e00\u4e2a\u4e2d\u95f4\u4ef6\uff0c\u5b9a\u4e49\u4e86\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u6570\u636e\u7c7b\u578b\u68c0\u6d4b\u65b9\u6cd5\u6765\u68c0\u6d4b<code style=\"color: #2c3e50;\">user id<\/code>\u7684\u7c7b\u578b\u6b63\u786e\u6027\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">param<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">param<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> validator<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">return<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> val<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">if<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">validator<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">val<\/span><span class=\"pun\" style=\"color: #666600;\">))<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">else<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">sendStatus<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">403<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">}<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">param<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'id'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">candidate<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">return<\/span><span class=\"pun\" style=\"color: #666600;\">!<\/span><span class=\"pln\" style=\"color: #000000;\">isNaN<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">parseFloat<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">candidate<\/span><span class=\"pun\" style=\"color: #666600;\">))<\/span><span class=\"pun\" style=\"color: #666600;\">&amp;&amp;<\/span><span class=\"pln\" style=\"color: #000000;\"> isFinite<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">candidate<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"routerroutepath\" style=\"color: #2c3e50;\" data-anchor-id=\"2115\">router.route(path)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"jjlf\">\u8fd4\u56de\u4e00\u4e2a\u5355\u4f8b\u6a21\u5f0f\u7684\u8def\u7531\u7684\u5b9e\u4f8b\uff0c\u4e4b\u540e\u4f60\u53ef\u4ee5\u5728\u5176\u4e0a\u65bd\u52a0\u5404\u79cdHTTP\u52a8\u4f5c\u7684\u4e2d\u95f4\u4ef6\u3002\u4f7f\u7528<code style=\"color: #2c3e50;\">app.route()<\/code>\u6765\u907f\u514d\u91cd\u590d\u8def\u7531\u540d\u5b57(\u56e0\u6b64\u9519\u5b57\u9519\u8bef)&#8211;\u540e\u9762\u8fd9\u53e5\u4e0d\u77e5\u9053\u8bf4\u7684\u4ec0\u4e48\u9b3c\uff0c\u5927\u6982\u7684\u610f\u601d\u5c31\u662f\u907f\u514d\u540c\u4e00\u4e2a\u8def\u5f84\u6709\u4e24\u4e2a\u8def\u7531\u5b9e\u4f8b\u3002<br \/>\n\u6784\u5efa\u5728\u4e0a\u9762\u7684<code style=\"color: #2c3e50;\">router.param()<\/code>\u4f8b\u5b50\u4e4b\u4e0a\uff0c\u4e0b\u9762\u7684\u4ee3\u7801\u5c55\u793a\u4e86\u600e\u4e48\u4f7f\u7528<code style=\"color: #2c3e50;\">router.route()<\/code>\u6765\u6307\u5b9a\u5404\u79cdHTTP\u65b9\u6cd5\u7684\u5904\u7406\u53e5\u67c4\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> router <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> express<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"typ\" style=\"color: #660066;\">Router<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">param<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'user_id'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> id<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ sample user, would actually fetch from DB, etc...<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">user <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> id<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"pln\" style=\"color: #000000;\">id<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> name<\/span><span class=\"pun\" style=\"color: #666600;\">:<\/span><span class=\"str\" style=\"color: #008800;\">\"TJ\"<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">};<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">route<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/users\/:user_id'<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">all<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ runs for all HTTP verbs first<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ think of it as route specific middleware!<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">})<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">get<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">json<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">user<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">})<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">put<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ just an example of maybe updating the user<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">user<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">name <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">params<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">name<\/span><span class=\"pun\" style=\"color: #666600;\">;<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ save user ... etc<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">json<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">user<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">})<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">post<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">new<\/span><span class=\"typ\" style=\"color: #660066;\">Error<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'not implemented'<\/span><span class=\"pun\" style=\"color: #666600;\">));<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">})<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">delete<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">new<\/span><span class=\"typ\" style=\"color: #660066;\">Error<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'not implemented'<\/span><span class=\"pun\" style=\"color: #666600;\">));<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">})<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"0go9\">\u8fd9\u79cd\u65b9\u6cd5\u91cd\u590d\u4f7f\u7528\u5355\u4e2a<code style=\"color: #2c3e50;\">\/usrs\/:user_id<\/code>\u8def\u5f84\u6765\u6dfb\u52a0\u4e86\u5404\u79cd\u7684HTTP\u65b9\u6cd5\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<h4 id=\"routerusepath-function-function\" style=\"color: #2c3e50;\" data-anchor-id=\"08ed\">router.use([path], [function, &#8230;] function)<\/h4>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"cnig\">\u7ed9\u53ef\u9009\u7684<code style=\"color: #2c3e50;\">path<\/code>\u53c2\u6570\u6307\u5b9a\u7684\u8def\u5f84\u6302\u8f7d\u7ed9\u5b9a\u7684\u4e2d\u95f4\u4ef6\u65b9\u6cd5\uff0c\u672a\u6307\u5b9a<code style=\"color: #2c3e50;\">path<\/code>\u53c2\u6570\uff0c\u9ed8\u8ba4\u503c\u4e3a<code style=\"color: #2c3e50;\">\/<\/code>\u3002<br \/>\n\u8fd9\u4e2a\u65b9\u6cd5\u7c7b\u4f3c\u4e8e<code style=\"color: #2c3e50;\">app.use()<\/code>\u3002\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\u548c\u7528\u4f8b\u5728\u4e0b\u9762\u63cf\u8ff0\u3002\u67e5\u9605<a style=\"color: #0088cc;\" href=\"http:\/\/expressjs.com\/en\/4x\/api.html#app.use\" target=\"_blank\">app.use()<\/a>\u83b7\u5f97\u66f4\u591a\u7684\u4fe1\u606f\u3002<br \/>\n\u4e2d\u95f4\u4ef6\u5c31\u50cf\u4e00\u4e2a\u6c34\u6696\u7ba1\u9053\uff0c\u8bf7\u6c42\u5728\u4f60\u5b9a\u4e49\u7684\u7b2c\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u5904\u5f00\u59cb\uff0c\u987a\u7740\u4e2d\u95f4\u4ef6\u5806\u6808\u4e00\u8def\u5f80\u4e0b\uff0c\u5982\u679c\u8def\u5f84\u5339\u914d\u5219\u5904\u7406\u8fd9\u4e2a\u8bf7\u6c42\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> express <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> require<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'express'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> app <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> express<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> router <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> express<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"typ\" style=\"color: #660066;\">Router<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ simple logger for this router`s requests<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ all requests to this router will first hit this middleware<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> console<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">log<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'%s %s %s'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">method<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">url<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> req<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">path<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">})<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ this will only be invoked if the path starts with \/bar form the mount ponit<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/bar'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ ... maybe some additional \/bar logging ...<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">();<\/span><\/code><\/li>\n<li class=\"L7\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">})<\/span><\/code><\/li>\n<li class=\"L8\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L9\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"com\" style=\"color: #880000;\">\/\/ always be invoked<\/span><\/code><\/li>\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> next<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'hello world'<\/span><span class=\"pun\" style=\"color: #666600;\">)\uff1b<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">})<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'\/foo'<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> router<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">listen<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"lit\" style=\"color: #006666;\">3000<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\" data-anchor-id=\"p2ur\">\u5bf9\u4e8e\u4e2d\u95f4\u4ef6<code style=\"color: #2c3e50;\">function<\/code>\uff0c\u6302\u8f7d\u7684\u8def\u5f84\u662f\u88ab\u5265\u79bb\u7684\u548c\u4e0d\u53ef\u89c1\u7684\u3002\u5173\u4e8e\u8fd9\u4e2a\u7279\u6027\u4e3b\u8981\u7684\u5f71\u54cd\u662f\u5bf9\u4e8e\u4e0d\u540c\u7684\u8def\u5f84\uff0c\u6302\u8f7d\u76f8\u540c\u7684\u4e2d\u95f4\u4ef6\u53ef\u80fd\u5bf9\u4ee3\u7801\u4e0d\u505a\u6539\u52a8\uff0c\u5c3d\u7ba1\u5176\u524d\u7f00\u5df2\u7ecf\u6539\u53d8\u3002<br \/>\n\u4f60\u4f7f\u7528<code style=\"color: #2c3e50;\">router.use()<\/code>\u5b9a\u4e49\u4e2d\u95f4\u4ef6\u7684\u987a\u5e8f\u5f88\u91cd\u8981\u3002\u4e2d\u95f4\u4eec\u662f\u6309\u5e8f\u88ab\u8c03\u7528\u7684\uff0c\u6240\u4ee5\u987a\u5e8f\u51b3\u5b9a\u4e86\u4e2d\u95f4\u4ef6\u7684\u4f18\u5148\u7ea7\u3002\u4f8b\u5982\uff0c\u901a\u5e38\u65e5\u5fd7\u662f\u4f60\u5c06\u4f7f\u7528\u7684\u7b2c\u4e00\u4e2a\u4e2d\u95f4\u4ef6\uff0c\u4ee5\u4fbf\u6bcf\u4e00\u4e2a\u8bf7\u6c42\u90fd\u88ab\u8bb0\u5f55\u3002<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"kwd\" style=\"color: #000088;\">var<\/span><span class=\"pln\" style=\"color: #000000;\"> logger <\/span><span class=\"pun\" style=\"color: #666600;\">=<\/span><span class=\"pln\" style=\"color: #000000;\"> require<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'morgan'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">logger<\/span><span class=\"pun\" style=\"color: #666600;\">());<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">express<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">static<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">__dirname <\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"str\" style=\"color: #008800;\">'\/public'<\/span><span class=\"pun\" style=\"color: #666600;\">));<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">)<\/span><span class=\"pun\" style=\"color: #666600;\">{<\/span><\/code><\/li>\n<li class=\"L5\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Hello'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L6\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\">\u73b0\u5728\u4e3a\u4e86\u652f\u6301\u4f60\u4e0d\u5e0c\u671b\u8bb0\u5f55\u9759\u6001\u6587\u4ef6\u8bf7\u6c42\uff0c\u4f46\u4e3a\u4e86\u7ee7\u7eed\u8bb0\u5f55\u90a3\u4e9b\u5b9a\u4e49\u5728<code style=\"color: #2c3e50;\">logger()<\/code>\u4e4b\u540e\u7684\u8def\u7531\u548c\u4e2d\u95f4\u4ef6\u3002\u4f60\u53ef\u4ee5\u7b80\u5355\u7684\u5c06<code style=\"color: #2c3e50;\">static()<\/code>\u79fb\u52a8\u5230\u524d\u9762\u6765\u89e3\u51b3\uff1a<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">express<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">static<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">__dirname <\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"str\" style=\"color: #008800;\">'\/public'<\/span><span class=\"pun\" style=\"color: #666600;\">));<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">logger<\/span><span class=\"pun\" style=\"color: #666600;\">());<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">router<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"kwd\" style=\"color: #000088;\">function<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">req<\/span><span class=\"pun\" style=\"color: #666600;\">,<\/span><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">){<\/span><\/code><\/li>\n<li class=\"L3\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\"> res<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">send<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"str\" style=\"color: #008800;\">'Hello'<\/span><span class=\"pun\" style=\"color: #666600;\">);<\/span><\/code><\/li>\n<li class=\"L4\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pun\" style=\"color: #666600;\">});<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\">\u53e6\u5916\u4e00\u4e2a\u786e\u51ff\u7684\u4f8b\u5b50\u662f\u4ece\u4e0d\u540c\u7684\u8def\u5f84\u6258\u7ba1\u9759\u6001\u6587\u4ef6\uff0c\u4f60\u53ef\u4ee5\u5c06<code style=\"color: #2c3e50;\">.\/public<\/code>\u653e\u5230\u524d\u9762\u6765\u83b7\u5f97\u66f4\u9ad8\u7684\u4f18\u5148\u7ea7:<\/p>\n<div class=\"md-section-divider\" style=\"color: #2c3e50;\"><\/div>\n<ol class=\"linenums\" style=\"color: rgba(102, 128, 153, 0.4);\">\n<li class=\"L0\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">express<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">static<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">__dirname <\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"str\" style=\"color: #008800;\">'\/public'<\/span><span class=\"pun\" style=\"color: #666600;\">));<\/span><\/code><\/li>\n<li class=\"L1\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">express<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">static<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">__dirname <\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"str\" style=\"color: #008800;\">'\/files'<\/span><span class=\"pun\" style=\"color: #666600;\">));<\/span><\/code><\/li>\n<li class=\"L2\"><code class=\"language-js\" style=\"color: inherit;\"><span class=\"pln\" style=\"color: #000000;\">app<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"pln\" style=\"color: #000000;\">use<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">express<\/span><span class=\"pun\" style=\"color: #666600;\">.<\/span><span class=\"kwd\" style=\"color: #000088;\">static<\/span><span class=\"pun\" style=\"color: #666600;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">__dirname <\/span><span class=\"pun\" style=\"color: #666600;\">+<\/span><span class=\"str\" style=\"color: #008800;\">'\/uploads'<\/span><span class=\"pun\" style=\"color: #666600;\">));<\/span><\/code><\/li>\n<\/ol>\n<p style=\"color: #2c3e50;\"><code style=\"color: #2c3e50;\">router.use()<\/code>\u65b9\u6cd5\u4e5f\u652f\u6301\u547d\u540d\u53c2\u6570\uff0c\u4ee5\u4fbf\u4f60\u7684\u6302\u8f7d\u70b9\u5bf9\u4e8e\u5176\u4ed6\u7684\u8def\u7531\u800c\u8a00\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u540d\u53c2\u6570\u6765\u8fdb\u884c\u9884\u52a0\u8f7d\uff0c\u8fd9\u6837\u505a\u662f\u5f88\u6709\u76ca\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6765\u6e90\uff1ahttps:\/\/www.zybuluo.com\/XiangZhou\/note\/208532 expres [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-5171","post","type-post","status-publish","format-standard","hentry","category-nodejs"],"_links":{"self":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/5171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5171"}],"version-history":[{"count":0,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/5171\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}