本文整理匯總了TypeScript中express.Router.route方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Router.route方法的具體用法?TypeScript Router.route怎麽用?TypeScript Router.route使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類express.Router
的用法示例。
在下文中一共展示了Router.route方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: constructor
constructor(public router: Router) {
router.route('/games/:gameName/tick/:currentState')
.post(tickQuestion);
router.route('/games/:gameName/tickRoundIntro')
.post(tickRoundIntro);
router.route('/games/:gameName/chooseAnswer')
.post(chooseAnswer);
router.route('/games/:gameName/answer')
.post(answer);
router.route('/games-join')
.post(join);
router.route('/games/:gameName/start')
.post(start);
router.route('/games/:gameName/createChild')
.post(createChild);
router.route('/games/:gameName')
.post(getGame);
router.route('/games-create')
.post(create);
}
示例2: routes
function routes(Book, resource) {
let bookRouter: Router = Router(),
bookCtrl = require('../controllers/book-ctrl')(Book, resource);
bookRouter.route('/:id/customEndpoint')
.get(bookCtrl.customEndpoint);
return bookRouter;
}
示例3: routes
function routes(User, resource) {
let userRouter: Router = Router(),
userCtrl = require('../controllers/user-ctrl')(User, resource);
userRouter.route('/:id/customEndpoint')
.get(userCtrl.customEndpoint);
return userRouter;
}
示例4: init
static init(app:Object, router:Router) {
app.use('/auth', AuthRoutes.init())
app.use('/user', UserRoutes.init())
app.use('/companies', CompanyRoutes.init())
router
.route('*')
.get(StaticDispatcher.sendIndex);
app.use('/', router);
}
示例5: function
/*
Routing usage:
1) 개별적으로 라우팅도 가능 ex) this._router.get('/', function(){...});
2) route() 함수로 같은 라우팅에 대한 다른 메소드를 묶어서 표현가능
ex) this._router.route(':id')
.get(function(){...})
.post(function(){...})
.put(function(){...})
.delete(function(){...})
.patch(function(){...});
*/
get routes(){
this._router.get('/', this._controller.retrive);
this._router.post('/', this._controller.create);
this._router.route('/:id')
.get(this._controller.findById)
.put(this._controller.update)
// .patch(this._controller.patch)
.delete(this._controller.delete);
return this._router;
}
示例6: Router
import {Request, Response, Router} from "express";
const router: Router = Router();
import {IRoute} from "express-serve-static-core";
import {bimModel} from "../models/models";
import {Stream} from "stream";
import {entityIO} from "../connections/socket";
const api: IRoute = router.route("/api/bim");
api.get(async (req: Request, res: Response) => {
let stream: Stream = await bimModel
.find({})
.lean(true)
.stream({ transform: JSON.stringify });
res.type("application/json");
stream.on("data", (doc: string) => {
// res.write();
entityIO.emit("entity", doc);
}).on("error", (err: Error) => {
console.log(err);
}).on("close", () => {
res.end(JSON.stringify({completed: true}));
});
});
export const apiBim = router;
示例7: Router
import {Request, Response, Router} from "express";
const router: Router = Router();
import {IRoute} from "express-serve-static-core";
import {objectModel} from "../models/models";
import {Stream} from "stream";
const api: IRoute = router.route("/api/object");
api.get(async (req: Request, res: Response) => {
let stream: Stream = await objectModel
.find({})
.stream({ transform: JSON.stringify });
stream.on("data", (doc: Object) => {
res.write(doc, "ascii");
}).on("error", (err: Error) => {
console.log(err);
}).on("close", () => {
res.end("Done");
});
});
export const apiObjects = router;
示例8: Router
import {Request, Response, Router} from "express";
const router: Router = Router();
import {IRoute} from "express-serve-static-core";
import {entityModel} from "../models/models";
import {Stream} from "stream";
import {entityIO} from "../connections/socket";
const api: IRoute = router.route("/api/entity");
api.get(async (req: Request, res: Response) => {
let stream: Stream = await entityModel
.find({})
.select({_id: 0, name: 1})
.lean(true)
.stream({ transform: JSON.stringify });
res.type("application/json");
stream.on("data", (doc: string) => {
// res.write();
entityIO.emit("entity", doc);
}).on("error", (err: Error) => {
console.log(err);
}).on("close", () => {
res.end(JSON.stringify({completed: true}));
});
});
export const apiEntities = router;
示例9: Router
/*
* Copyright (C) 2016 Juergen Zimmermann, Hochschule Karlsruhe
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import {Router} from 'express';
// MIME-Typ application/x-www-form-urlencoded
import {urlencoded} from 'body-parser';
import {login} from './iam_request_handler';
const loginRouter: Router = Router();
loginRouter.route('/').post(
urlencoded({extended: false, type: 'application/x-www-form-urlencoded'}),
login);
export default loginRouter;
示例10: 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;