當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Router.param方法代碼示例

本文整理匯總了TypeScript中express.Router.param方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Router.param方法的具體用法?TypeScript Router.param怎麽用?TypeScript Router.param使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在express.Router的用法示例。


在下文中一共展示了Router.param方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: mount

  mount(router: Router) {
    var controller = require(this.controller)

    // if there is a target method, check to see if it exists and replace the original controller with it
    if (this.target) {
      if (!controller.hasOwnProperty(this.target)) {
        throw new Error("target function " + this.target + " does not exist on controller " + this.controller)
      }
      controller = controller[this.target]
    }

    // if controller is not a function, throw an error
    if (typeof (controller) != "function") {
      throw new Error("controllers must resolve to a function")
    }

    // use a switch (rather than checking for the method) to prevent 
    // unwanted method calls (ie. router.route(this.path, controller) would not be good...)
    switch (this.method.toLowerCase()) {
      case "all":
        router.all(this.path, controller)
        break
      case "get":
        router.get(this.path, controller)
        break
      case "put":
        router.put(this.path, controller)
        break
      case "post":
        router.post(this.path, controller)
        break
      case "delete":
        router.delete(this.path, controller)
        break
      case "patch":
        router.patch(this.path, controller)
        break
      case "use":
        if (typeof this.path === "string") {
          router.use(this.path, controller);
        } else {
          router.use(controller);
        }
        break;
      case "param":
        if (typeof this.path === "string") {
          router.param(this.path, controller);
        } else {
          router.param(controller);
        }
        break;
      default:
        throw new Error("unsupported method " + this.method)
    }
  }
開發者ID:Beng89,項目名稱:adv-route,代碼行數:55,代碼來源:route.ts

示例2: Router

import {Router} from 'express';

// Einlesen von application/json im Request-Rumpf
import {json} from 'body-parser';

import {
    getById,
    getByQuery,
    post,
    put,
    deleteFn
} from './router/videos_request_handler';
import {
    isAdmin,
    isAdminMitarbeiter
} from '../iam/router/iam_request_handler';
import {validateMongoId} from '../shared/shared';

// http://expressjs.com/en/api.html
const videosRouter: Router = Router();
videosRouter.route('/')
    .get(getByQuery)
    .post(isAdminMitarbeiter, json(), post)
    .put(isAdminMitarbeiter, json(), put);

videosRouter.param('id', validateMongoId)
    .get('/:id', getById)
    .delete('/:id', isAdmin, deleteFn);

export default videosRouter;
開發者ID:Zenthu,項目名稱:VP,代碼行數:30,代碼來源:index.ts

示例3: Router

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/* tslint:disable:max-line-length */
import {Router} from 'express';

// Einlesen von application/json im Request-Rumpf
// Fuer multimediale Daten (Videos, Bilder, Audios): raw-body
import {json} from 'body-parser';

import {getById, getByQuery, post, put, deleteFn} from './kanaele_request_handler';
import {validateJwt, isAdmin, isAdminMitarbeiter} from '../../iam/router/iam_request_handler';
import {validateMongoId} from '../../shared/shared';
/* tslint:enable:max-line-length */

// http://expressjs.com/en/api.html
// Ein Router ist eine "Mini-Anwendung" mit Express
const kanaeleRouter: Router = Router();
kanaeleRouter.route('/')
    .get(getByQuery)
    .post(validateJwt, isAdminMitarbeiter, json(), post)
    .put(validateJwt, isAdminMitarbeiter, json(), put);

const idParam: string = 'id';
kanaeleRouter.param(idParam, validateMongoId)
    .get(`/:${idParam}`, getById)
    .delete(`/:${idParam}`, validateJwt, isAdmin, deleteFn);

export default kanaeleRouter;
開發者ID:Zenthu,項目名稱:VP,代碼行數:30,代碼來源:index.ts

示例4: Router

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/* tslint:disable:max-line-length */
import {Router} from 'express';

// Einlesen von application/json im Request-Rumpf
// Fuer multimediale Daten (Videos, Bilder, Audios): raw-body
import {json} from 'body-parser';

import {getById, getByQuery, post, put, deleteFn} from './videos_request_handler';
import {validateJwt, isAdmin, isAdminMitarbeiter} from '../../iam/router/iam_request_handler';
import {validateMongoId} from '../../shared/shared';
/* tslint:enable:max-line-length */

// http://expressjs.com/en/api.html
// Ein Router ist eine "Mini-Anwendung" mit Express
const videosRouter: Router = Router();
videosRouter.route('/')
    .get(getByQuery)
    .post(validateJwt, isAdminMitarbeiter, json(), post)
    .put(validateJwt, isAdminMitarbeiter, json(), put);

const idParam: string = 'id';
videosRouter.param(idParam, validateMongoId)
    .get(`/:${idParam}`, getById)
    .delete(`/:${idParam}`, validateJwt, isAdmin, deleteFn);

export default videosRouter;
開發者ID:Zenthu,項目名稱:VP,代碼行數:30,代碼來源:index.ts

示例5: Router

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/* tslint:disable:max-line-length */
import {Router} from 'express';

// Einlesen von application/json im Request-Rumpf
// Fuer multimediale Daten (Videos, Bilder, Audios): raw-body
import {json} from 'body-parser';

import {getById, getByQuery, post, put, deleteFn} from './videos_request_handler';
import {validateJwt, isAdmin, isAdminMitarbeiter} from '../../iam/router/iam_request_handler';
import {validateMongoId} from '../../shared/shared';
/* tslint:enable:max-line-length */

// http://expressjs.com/en/api.html
// Ein Router ist eine "Mini-Anwendung" mit Express
const buecherRouter: Router = Router();
buecherRouter.route('/')
    .get(getByQuery)
    .post(validateJwt, isAdminMitarbeiter, json(), post)
    .put(validateJwt, isAdminMitarbeiter, json(), put);

const idParam: string = 'id';
buecherRouter.param(idParam, validateMongoId)
    .get(`/:${idParam}`, getById)
    .delete(`/:${idParam}`, validateJwt, isAdmin, deleteFn);

export default buecherRouter;
開發者ID:AdrianFoell,項目名稱:VP,代碼行數:30,代碼來源:index.ts


注:本文中的express.Router.param方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。