');display:flex;inset:0;justify-content:center;position:absolute}.copy-to-clipboard-button[data-copy-state=copy-success]:before{content:url('data:image/svg+xml;utf8, ')}.kg-bookmark-card figcaption,.kg-gallery-card figcaption,.kg-image-card figcaption,.kg-video-card figcaption{padding-top:2px;text-align:center;--tw-text-opacity:1;color:rgb(71 85 105/var(--tw-text-opacity,1))}.kg-bookmark-card figcaption:is(.dark *),.kg-gallery-card figcaption:is(.dark *),.kg-image-card figcaption:is(.dark *),.kg-video-card figcaption:is(.dark *){--tw-text-opacity:1;color:rgb(203 213 225/var(--tw-text-opacity,1))}.kg-code-card figcaption{padding-top:2px;text-align:center;--tw-text-opacity:1;color:rgb(71 85 105/var(--tw-text-opacity,1))}.kg-code-card figcaption:is(.dark *){--tw-text-opacity:1;color:rgb(15 23 42/var(--tw-text-opacity,1))}.toc{overflow-y:auto}.toc>.toc-list{overflow:hidden;position:relative}.toc>.toc-list li{list-style:none}.js-toc{overflow-y:hidden}.toc-list{margin:0;padding-left:1.5rem}a.toc-link{color:currentColor;height:100%}.is-collapsible{max-height:1000px;overflow:hidden;transition:all .3s ease-in-out}.is-collapsed{max-height:0}.is-position-fixed{position:fixed!important;top:0}.is-active-link{font-weight:700}.toc-link:before{background-color:#eee;content:" ";display:inline-block;height:inherit;left:0;margin-top:-1px;position:absolute;width:2px}.is-active-link:before{background-color:#54bc4b}.toc-list-item{font-size:.95rem;margin-bottom:.5rem}.toc-link{border-radius:.25rem;color:#333;display:block;padding:.25rem .5rem;text-decoration:none;transition:color .2s ease}.toc-link:hover{background-color:#f3f4f6;color:#1e40af}.toc-link.is-active-link{background-color:#e0e7ff;color:#1e40af;font-weight:600}.toc-link.node-name--H2{font-size:1rem}.content img[width="20"],.content img[width="25"]{display:inline;margin-left:.25rem;margin-right:.25rem}.content table td[colspan="2"]{text-align:center}.content table td img{margin:auto}.first-letter\:uppercase:first-letter{text-transform:uppercase}.hover\:scale-110:hover{--tw-scale-x:1.1;--tw-scale-y:1.1;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.hover\:border-blue-400:hover{--tw-border-opacity:1;border-color:rgb(96 165 250/var(--tw-border-opacity,1))}.hover\:border-secondary-300:hover{--tw-border-opacity:1;border-color:rgb(203 213 225/var(--tw-border-opacity,1))}.hover\:bg-blue-700:hover{--tw-bg-opacity:1;background-color:rgb(29 78 216/var(--tw-bg-opacity,1))}.hover\:bg-gray-100:hover{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity,1))}.hover\:bg-gray-50:hover{--tw-bg-opacity:1;background-color:rgb(249 250 251/var(--tw-bg-opacity,1))}.hover\:bg-primary-100:hover{--tw-bg-opacity:1;background-color:rgb(224 242 254/var(--tw-bg-opacity,1))}.hover\:bg-primary-200:hover{--tw-bg-opacity:1;background-color:rgb(186 230 253/var(--tw-bg-opacity,1))}.hover\:bg-primary-50:hover{--tw-bg-opacity:1;background-color:rgb(240 249 255/var(--tw-bg-opacity,1))}.hover\:bg-primary-50\/80:hover{background-color:rgba(240,249,255,.8)}.hover\:bg-primary-700:hover{--tw-bg-opacity:1;background-color:rgb(29 78 216/var(--tw-bg-opacity,1))}.hover\:bg-red-100:hover{--tw-bg-opacity:1;background-color:rgb(254 226 226/var(--tw-bg-opacity,1))}.hover\:bg-secondary-100:hover{--tw-bg-opacity:1;background-color:rgb(241 245 249/var(--tw-bg-opacity,1))}.hover\:from-blue-600:hover{--tw-gradient-from:#2563eb var(--tw-gradient-from-position);--tw-gradient-to:rgba(37,99,235,0) var(--tw-gradient-to-position);--tw-gradient-stops:var(--tw-gradient-from),var(--tw-gradient-to)}.hover\:to-blue-700:hover{--tw-gradient-to:#1d4ed8 var(--tw-gradient-to-position)}.hover\:text-accent-600:hover{--tw-text-opacity:1;color:rgb(217 119 6/var(--tw-text-opacity,1))}.hover\:text-blue-600:hover{--tw-text-opacity:1;color:rgb(37 99 235/var(--tw-text-opacity,1))}.hover\:text-blue-800:hover{--tw-text-opacity:1;color:rgb(30 64 175/var(--tw-text-opacity,1))}.hover\:text-gray-400:hover{--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity,1))}.hover\:text-gray-700:hover{--tw-text-opacity:1;color:rgb(55 65 81/var(--tw-text-opacity,1))}.hover\:text-green-600:hover{--tw-text-opacity:1;color:rgb(22 163 74/var(--tw-text-opacity,1))}.hover\:text-primary-600:hover{--tw-text-opacity:1;color:rgb(37 99 235/var(--tw-text-opacity,1))}.hover\:text-primary-700:hover{--tw-text-opacity:1;color:rgb(29 78 216/var(--tw-text-opacity,1))}.hover\:text-secondary-50:hover{--tw-text-opacity:1;color:rgb(248 250 252/var(--tw-text-opacity,1))}.hover\:text-secondary-700:hover{--tw-text-opacity:1;color:rgb(51 65 85/var(--tw-text-opacity,1))}.hover\:opacity-90:hover{opacity:.9}.hover\:shadow-lg:hover{--tw-shadow:0 10px 15px -3px rgba(0,0,0,.1),0 4px 6px -4px rgba(0,0,0,.1);--tw-shadow-colored:0 10px 15px -3px var(--tw-shadow-color),0 4px 6px -4px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.focus\:border-transparent:focus{border-color:transparent}.focus\:bg-primary-50:focus{--tw-bg-opacity:1;background-color:rgb(240 249 255/var(--tw-bg-opacity,1))}.focus\:text-primary-600:focus{--tw-text-opacity:1;color:rgb(37 99 235/var(--tw-text-opacity,1))}.focus\:outline-none:focus{outline:2px solid transparent;outline-offset:2px}.focus\:ring-1:focus{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus\:ring-blue-500:focus{--tw-ring-opacity:1;--tw-ring-color:rgb(59 130 246/var(--tw-ring-opacity,1))}.focus\:ring-gray-500:focus{--tw-ring-opacity:1;--tw-ring-color:rgb(107 114 128/var(--tw-ring-opacity,1))}.focus\:ring-offset-2:focus{--tw-ring-offset-width:2px}.group:focus-within .group-focus-within\:opacity-100{opacity:1}.group:hover .group-hover\:visible,.group\/level2:hover .group-hover\/level2\:visible{visibility:visible}.group:hover .group-hover\:block{display:block}.group\/item:hover .group-hover\/item\:translate-x-1{--tw-translate-x:0.25rem}.group\/item:hover .group-hover\/item\:translate-x-1,.group\/level2:hover .group-hover\/level2\:translate-x-0{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.group\/level2:hover .group-hover\/level2\:translate-x-0{--tw-translate-x:0px}.group\/level2:hover .group-hover\/level2\:translate-x-1{--tw-translate-x:0.25rem}.group:hover .group-hover\:-translate-x-1,.group\/level2:hover .group-hover\/level2\:translate-x-1{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.group:hover .group-hover\:-translate-x-1{--tw-translate-x:-0.25rem}.group:hover .group-hover\:translate-x-1{--tw-translate-x:0.25rem}.group:hover .group-hover\:rotate-180,.group:hover .group-hover\:translate-x-1{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.group:hover .group-hover\:rotate-180{--tw-rotate:180deg}.group\/bookmark:hover .group-hover\/bookmark\:fill-current,.group\/comment:hover .group-hover\/comment\:fill-current,.group\/like:hover .group-hover\/like\:fill-current{fill:currentColor}.group:hover .group-hover\:fill-black\/75{fill:rgba(0,0,0,.75)}.group:hover .group-hover\:fill-current{fill:currentColor}.group:hover .group-hover\:text-primary-600{--tw-text-opacity:1;color:rgb(37 99 235/var(--tw-text-opacity,1))}.group:hover .group-hover\:opacity-100,.group\/level2:hover .group-hover\/level2\:opacity-100{opacity:1}.dark\:border-primary-400:is(.dark *){--tw-border-opacity:1;border-color:rgb(56 189 248/var(--tw-border-opacity,1))}.dark\:border-secondary-200:is(.dark *){--tw-border-opacity:1;border-color:rgb(226 232 240/var(--tw-border-opacity,1))}.dark\:border-secondary-600:is(.dark *){--tw-border-opacity:1;border-color:rgb(71 85 105/var(--tw-border-opacity,1))}.dark\:border-secondary-700:is(.dark *){--tw-border-opacity:1;border-color:rgb(51 65 85/var(--tw-border-opacity,1))}.dark\:bg-blue-900\/20:is(.dark *){background-color:rgba(30,58,138,.2)}.dark\:bg-gray-800:is(.dark *){--tw-bg-opacity:1;background-color:rgb(31 41 55/var(--tw-bg-opacity,1))}.dark\:bg-gray-800\/95:is(.dark *){background-color:rgba(31,41,55,.95)}.dark\:bg-gray-900:is(.dark *){--tw-bg-opacity:1;background-color:rgb(17 24 39/var(--tw-bg-opacity,1))}.dark\:bg-gray-900\/80:is(.dark *){background-color:rgba(17,24,39,.8)}.dark\:bg-primary-900:is(.dark *){--tw-bg-opacity:1;background-color:rgb(30 58 138/var(--tw-bg-opacity,1))}.dark\:bg-secondary-700:is(.dark *){--tw-bg-opacity:1;background-color:rgb(51 65 85/var(--tw-bg-opacity,1))}.dark\:bg-secondary-800:is(.dark *){--tw-bg-opacity:1;background-color:rgb(30 41 59/var(--tw-bg-opacity,1))}.dark\:bg-secondary-900:is(.dark *){--tw-bg-opacity:1;background-color:rgb(15 23 42/var(--tw-bg-opacity,1))}.dark\:bg-slate-400:is(.dark *){--tw-bg-opacity:1;background-color:rgb(148 163 184/var(--tw-bg-opacity,1))}.dark\:fill-white\/60:is(.dark *){fill:hsla(0,0%,100%,.6)}.dark\:fill-white\/70:is(.dark *){fill:hsla(0,0%,100%,.7)}.dark\:stroke-white\/60:is(.dark *){stroke:hsla(0,0%,100%,.6)}.dark\:text-\[rgba\(255\2c 255\2c 255\2c 0\.5\)\]:is(.dark *){color:hsla(0,0%,100%,.5)}.dark\:text-blue-400:is(.dark *){--tw-text-opacity:1;color:rgb(96 165 250/var(--tw-text-opacity,1))}.dark\:text-gray-100:is(.dark *){--tw-text-opacity:1;color:rgb(243 244 246/var(--tw-text-opacity,1))}.dark\:text-gray-200:is(.dark *){--tw-text-opacity:1;color:rgb(229 231 235/var(--tw-text-opacity,1))}.dark\:text-gray-300:is(.dark *){--tw-text-opacity:1;color:rgb(209 213 219/var(--tw-text-opacity,1))}.dark\:text-gray-400:is(.dark *){--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity,1))}.dark\:text-primary-400:is(.dark *){--tw-text-opacity:1;color:rgb(56 189 248/var(--tw-text-opacity,1))}.dark\:text-secondary-100:is(.dark *){--tw-text-opacity:1;color:rgb(241 245 249/var(--tw-text-opacity,1))}.dark\:text-secondary-300:is(.dark *){--tw-text-opacity:1;color:rgb(203 213 225/var(--tw-text-opacity,1))}.dark\:text-secondary-400:is(.dark *){--tw-text-opacity:1;color:rgb(148 163 184/var(--tw-text-opacity,1))}.dark\:text-secondary-600:is(.dark *){--tw-text-opacity:1;color:rgb(71 85 105/var(--tw-text-opacity,1))}.dark\:text-slate-200:is(.dark *){--tw-text-opacity:1;color:rgb(226 232 240/var(--tw-text-opacity,1))}.dark\:text-white:is(.dark *){--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity,1))}.dark\:shadow-gray-800\/50:is(.dark *){--tw-shadow-color:rgba(31,41,55,.5);--tw-shadow:var(--tw-shadow-colored)}.dark\:shadow-gray-900\/50:is(.dark *){--tw-shadow-color:rgba(17,24,39,.5);--tw-shadow:var(--tw-shadow-colored)}.dark\:ring-gray-700:is(.dark *){--tw-ring-opacity:1;--tw-ring-color:rgb(55 65 81/var(--tw-ring-opacity,1))}.dark\:ring-secondary-600:is(.dark *){--tw-ring-opacity:1;--tw-ring-color:rgb(71 85 105/var(--tw-ring-opacity,1))}.dark\:hover\:border-secondary-600:hover:is(.dark *){--tw-border-opacity:1;border-color:rgb(71 85 105/var(--tw-border-opacity,1))}.dark\:hover\:bg-gray-700:hover:is(.dark *){--tw-bg-opacity:1;background-color:rgb(55 65 81/var(--tw-bg-opacity,1))}.dark\:hover\:bg-gray-700\/80:hover:is(.dark *){background-color:rgba(55,65,81,.8)}.dark\:hover\:bg-gray-800:hover:is(.dark *){--tw-bg-opacity:1;background-color:rgb(31 41 55/var(--tw-bg-opacity,1))}.dark\:hover\:bg-primary-400:hover:is(.dark *){--tw-bg-opacity:1;background-color:rgb(56 189 248/var(--tw-bg-opacity,1))}.dark\:hover\:bg-secondary-700:hover:is(.dark *){--tw-bg-opacity:1;background-color:rgb(51 65 85/var(--tw-bg-opacity,1))}.dark\:hover\:text-accent-400:hover:is(.dark *){--tw-text-opacity:1;color:rgb(251 191 36/var(--tw-text-opacity,1))}.dark\:hover\:text-gray-200:hover:is(.dark *){--tw-text-opacity:1;color:rgb(229 231 235/var(--tw-text-opacity,1))}.dark\:hover\:text-green-400:hover:is(.dark *){--tw-text-opacity:1;color:rgb(74 222 128/var(--tw-text-opacity,1))}.dark\:hover\:text-primary-300:hover:is(.dark *){--tw-text-opacity:1;color:rgb(125 211 252/var(--tw-text-opacity,1))}.dark\:hover\:text-primary-400:hover:is(.dark *){--tw-text-opacity:1;color:rgb(56 189 248/var(--tw-text-opacity,1))}.dark\:hover\:text-secondary-300:hover:is(.dark *){--tw-text-opacity:1;color:rgb(203 213 225/var(--tw-text-opacity,1))}.dark\:hover\:text-secondary-50:hover:is(.dark *){--tw-text-opacity:1;color:rgb(248 250 252/var(--tw-text-opacity,1))}.dark\:focus\:bg-gray-700:focus:is(.dark *){--tw-bg-opacity:1;background-color:rgb(55 65 81/var(--tw-bg-opacity,1))}.dark\:focus\:bg-gray-800:focus:is(.dark *){--tw-bg-opacity:1;background-color:rgb(31 41 55/var(--tw-bg-opacity,1))}.dark\:focus\:text-primary-400:focus:is(.dark *){--tw-text-opacity:1;color:rgb(56 189 248/var(--tw-text-opacity,1))}.dark\:focus\:ring-offset-gray-800:focus:is(.dark *){--tw-ring-offset-color:#1f2937}.dark\:focus\:ring-offset-gray-900:focus:is(.dark *){--tw-ring-offset-color:#111827}.dark\:focus\:ring-offset-secondary-800:focus:is(.dark *){--tw-ring-offset-color:#1e293b}.dark\:focus\:ring-offset-secondary-900:focus:is(.dark *){--tw-ring-offset-color:#0f172a}.group:hover .dark\:group-hover\:fill-white\/75:is(.dark *){fill:hsla(0,0%,100%,.75)}.group:hover .dark\:group-hover\:text-primary-400:is(.dark *){--tw-text-opacity:1;color:rgb(56 189 248/var(--tw-text-opacity,1))}@media (min-width:640px){.sm\:col-span-1{grid-column:span 1/span 1}.sm\:mx-1{margin-left:.25rem;margin-right:.25rem}.sm\:mx-2{margin-left:.5rem;margin-right:.5rem}.sm\:inline{display:inline}.sm\:max-w-screen-sm{max-width:640px}.sm\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.sm\:p-8{padding:2rem}.sm\:px-5{padding-left:1.25rem;padding-right:1.25rem}.sm\:px-6{padding-left:1.5rem;padding-right:1.5rem}.sm\:px-8{padding-left:2rem;padding-right:2rem}.sm\:py-10{padding-bottom:2.5rem;padding-top:2.5rem}.sm\:py-3{padding-bottom:.75rem;padding-top:.75rem}}@media (min-width:768px){.md\:col-span-1{grid-column:span 1/span 1}.md\:h-14{height:3.5rem}.md\:h-96{height:24rem}.md\:w-14{width:3.5rem}.md\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.md\:grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}.md\:flex-row{flex-direction:row}.md\:text-4xl{font-size:2.25rem;line-height:2.5rem}}@media (min-width:1024px){.lg\:invisible{visibility:hidden}.lg\:absolute{position:absolute}.lg\:left-0{left:0}.lg\:col-span-1{grid-column:span 1/span 1}.lg\:col-span-2{grid-column:span 2/span 2}.lg\:col-span-3{grid-column:span 3/span 3}.lg\:row-span-3{grid-row:span 3/span 3}.lg\:row-span-4{grid-row:span 4/span 4}.lg\:row-span-6{grid-row:span 6/span 6}.lg\:mt-2{margin-top:.5rem}.lg\:block{display:block}.lg\:inline{display:inline}.lg\:flex{display:flex}.lg\:hidden{display:none}.lg\:h-\[496px\]{height:496px}.lg\:w-48{width:12rem}.lg\:grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.lg\:grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}.lg\:grid-cols-5{grid-template-columns:repeat(5,minmax(0,1fr))}.lg\:grid-cols-\[auto_1fr_auto\]{grid-template-columns:auto 1fr auto}.lg\:flex-row{flex-direction:row}.lg\:items-center{align-items:center}.lg\:gap-2{gap:.5rem}.lg\:rounded-lg{border-radius:.5rem}.lg\:p-6{padding:1.5rem}.lg\:px-8{padding-left:2rem;padding-right:2rem}.lg\:py-2{padding-bottom:.5rem;padding-top:.5rem}.lg\:pl-0{padding-left:0}.lg\:text-3xl{font-size:1.875rem;line-height:2.25rem}.lg\:text-5xl{font-size:3rem;line-height:1}.lg\:opacity-0{opacity:0}.lg\:shadow-lg{--tw-shadow:0 10px 15px -3px rgba(0,0,0,.1),0 4px 6px -4px rgba(0,0,0,.1);--tw-shadow-colored:0 10px 15px -3px var(--tw-shadow-color),0 4px 6px -4px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.lg\:ring-1{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.lg\:ring-black{--tw-ring-opacity:1;--tw-ring-color:rgb(0 0 0/var(--tw-ring-opacity,1))}.lg\:ring-opacity-5{--tw-ring-opacity:0.05}.group:focus-within .lg\:group-focus-within\:visible{visibility:visible}.group:hover .lg\:group-hover\:visible{visibility:visible}.group:hover .lg\:group-hover\:opacity-100{opacity:1}.dark\:lg\:shadow-gray-900\/50:is(.dark *){--tw-shadow-color:rgba(17,24,39,.5);--tw-shadow:var(--tw-shadow-colored)}.dark\:lg\:ring-gray-700:is(.dark *){--tw-ring-opacity:1;--tw-ring-color:rgb(55 65 81/var(--tw-ring-opacity,1))}}.gh-post-upgrade-cta{align-items:center;color:#fff;display:flex;flex-direction:column;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Open Sans,Helvetica Neue,sans-serif;font-size:16px;text-align:center;width:100%}.gh-post-upgrade-cta-content{border-radius:8px;padding:40px 4vw}.gh-post-upgrade-cta h2{color:#fff;font-size:28px;letter-spacing:-.2px;margin:0;padding:0}.gh-post-upgrade-cta p{margin:20px 0 0;padding:0}.gh-post-upgrade-cta small{font-size:16px;letter-spacing:-.2px}.gh-post-upgrade-cta a{cursor:pointer;font-weight:500}.gh-post-upgrade-cta a,.gh-post-upgrade-cta a:hover{box-shadow:none;color:#fff;text-decoration:underline}.gh-post-upgrade-cta a:hover{opacity:.8}.gh-post-upgrade-cta a.gh-btn{background:#fff;border-radius:4px;display:block;font-size:16px;font-weight:600;margin:28px 0 0;padding:8px 18px;text-decoration:none}.gh-post-upgrade-cta a.gh-btn:hover{opacity:.92}#search.loading{pointer-events:none}#search.loading i,#search.loading span,#search.loading svg{opacity:0;visibility:hidden}#search.loading:before{animation:search-loading-spin .8s linear infinite;border:3px solid rgba(0,0,0,.1);border-radius:50%;border-top-color:currentcolor;height:20px;margin:-10px 0 0 -10px;width:20px;z-index:1}#search.loading:after,#search.loading:before{content:"";left:50%;position:absolute;top:50%}#search.loading:after{animation:search-loading-pulse 1.5s ease-in-out infinite;background:rgba(0,0,0,.05);border-radius:50%;height:32px;margin:-16px 0 0 -16px;width:32px}@keyframes search-loading-spin{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}@keyframes search-loading-pulse{0%,to{opacity:.5;transform:scale(.8)}50%{opacity:.8;transform:scale(1.2)}}
Middleware is a function with access to the request object (req), the response object (res), and the next middleware in the application’s request-response cycle, commonly denoted by a variable named next.
中间件是函数,在应用程序请求响应周期内可以访问request请求对象和response对象并且执行下一个中间件
中间件可以做那些事 Execute any code. 执行任何代码 Make changes to the request and the response objects. 修改请求和响应对象 End the request-response cycle. 结束请求响应周期 Call the next middleware in the stack. 回调下一个中间件 简单的中间件 var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
});
app.listen(3000);
Here is a simple example of middleware called “myLogger”. All it does is print “LOGGED”, when a request to the app passes through it. The middleware is assigned to a variable named myLogger.
下面是中间件示例叫myLogger,当一个请求到达时,它总是打印LOGGED,并把中间件赋给名称为myLogger的变量
var myLogger = function (req, res, next) {
console.log('LOGGED');
next();
};
当调用next方法时,将会执行下一个函数,next方法不是Node 或者 Express 的API,但是可以通过第三个参数传入中间件,可以在任何地方回调它
To load the middleware, call app.use() with the middleware function. For example, the following code loads this middleware before the route to the root path (/).
app.use()可以载入中间件函数,比如在root路由中载入中间件
var express = require('express');
var app = express();
var myLogger = function (req, res, next) {
console.log('LOGGED');
next();
};
app.use(myLogger);
app.get('/', function (req, res) {
res.send('Hello World!');
});
app.listen(3000);
Now every time the app receives a request, it will print “LOGGED” to the terminal.
现在每次app接收到请求时都会在终端打印LOGGED
The order of middleware loading is important: middleware loaded first is executed first.
中间件载入顺序是非常重要的,首先要载入才能执行
If myLogger was loaded after the route to the root path, the request would have never reached it, and the app wouldn’t print “LOGGED”, because the route handler of the root path would have terminated the request-response cycle.
如果myLogger在root路由之后在载入,App永远都不会执行这个中间件,并且不会打印LOGGED,因为中间件不在请求-响应周期内
The middleware myLogger simply printed a message and passed on the request to the next middleware in the stack by calling next().
中间件myLogger 只是简单打印一个消息并且使用next()回调下一个中间件
The next example adds a property called requestTime to the request object. So, we’ll call this middleware “requestTime”.
下一个示例添加一个属性称为requestTime
var requestTime = function (req, res, next) {
req.requestTime = Date.now();
next();
};
......
var express = require('express');
var app = express();
var requestTime = function (req, res, next) {
req.requestTime = Date.now();
next();
};
app.use(requestTime);
app.get('/', function (req, res) {
var responseText = 'Hello World!<br>';
responseText += '<small>Requested at: ' + req.requestTime + '</small>';
res.send(responseText);
});
app.listen(3000);
© 2025 myfreax. All rights reserved.