<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          express-coroutineExpress 中使用 Generator 方法

          聯(lián)合創(chuàng)作 · 2023-09-23 15:12

          在 Express 中像 Koa 那樣使用 Generator 方法。

          安裝:

          npm install express-coroutine --save

          初始化:

          // Init express
          
          const express = require('express-coroutine')(require('express'));
          const app = express();
          
          // Init router
          
          const express = require('express-coroutine')(require('express'));
          const app = express();
          const router = new expressGenerators.Router();
          app.use(router);
          
          router.get('/', function* (req, res) {
            res.send('it works!');
          });

          使用:

          const express = require('express-coroutine')(require('express'));
          
          const app = express();
          
          app.get('/user/:id', function* (req, res) {
            const user = yield User.findById(req.params.id);
            res.send(user);
          })
          
          app.get('/error', function* (req, res) {
            throw new Error('Bang!');
          });
          
          app.listen(8000);

          更多用法詳見測試文件:https://github.com/yourtion/express-coroutine/blob/master/test.js

          瀏覽 24
          點贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  亚洲三级片无码 | 亚州无码 | 亚洲无码小说 | 日韩国产精品一级片 | 激情性爱网站 |