<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # middleware ## 中間件 ~~~ function middleware(req, res, next) { // req.url starts with "/foo" res.end('Hello from Connect2!\n'); } ~~~ 說明 * req是請求 * res是響應 * next是如果當前中間件不處理,就讓下一個中間件處理 ## 筒子理論 connect里 ~~~ var connect = require('connect') var http = require('http') var app = connect() // respond to all requests app.use(function(req, res){ res.end('Hello from Connect!\n'); }) app.use('/2', function fooMiddleware(req, res, next) { // req.url starts with "/foo" res.end('Hello from Connect2!\n'); }); //create node.js http server and listen on port http.createServer(app).listen(3011) ~~~ ![](https://i5ting.github.io/wechat-dev-with-nodejs/express/2.png) ## 變胖的筒子 express對某個中間件的筒子變胖理論 ~~~ var express = require('express'); var app = express(); function m1(req, res) { console.log('m1...'); } function m2(req, res) { console.log('m2...'); } app.get('/', m1, m2, function (req, res) { res.send('Hello World') }) // 隨機端口3000 - 10000 之間 app.listen(4001) ~~~ 在這個請求定義中,使用了m1和m2中間件,他們都沒有處理具體內容,直接next下一個中間件去處理,即最后的那個匿名函數。 ![](https://i5ting.github.io/wechat-dev-with-nodejs/express/3.png) ## 中間件分類:全局和路由里的 ~~~ var express = require('express'); var app = express(); app.use(function (req, res, next) { res.send('global middleware....') }) function m1(req, res) { console.log('m1...'); } function m2(req, res) { console.log('m2...'); } app.get('/', m1, m2, function (req, res) { res.send('Hello World') }) // 隨機端口3000 - 10000 之間 app.listen(4001) ~~~ * 全局的,出自connect(筒子) * 路由里的,出自express(變胖的筒子) ## 總結 ![](https://i5ting.github.io/wechat-dev-with-nodejs/express/1.JPG) * 空項目 * connect的筒子理論 * express對某個中間件的筒子變胖理論
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看