本文整理匯總了TypeScript中express.Router函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript Router函數的具體用法?TypeScript Router怎麽用?TypeScript Router使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Router函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: pNext
}catch(pErr){
console.log('Error while parsing token : ' + pErr);
pResponse.sendStatus(403);
}
}
}
// Sanitize all the parameter send with POST request
if(pRequest.method === 'POST') {
for(let param in pRequest.body) {
pRequest.body[param] = vValidator.escape(pRequest.body[param]);
}
}
pNext();
});
var vRouter = vExpress.Router();
vRouter.post('/login',vLoginCtrl.login);
vRouter.post('/login/MPIN', vLoginCtrl.submitMPIN);
vRouter.get('/logout', vLoginCtrl.logout);
vRouter.get('/retailer/alert',vRetailerCtrl.getAllRetailerAlert);
vRouter.post('/getSalesRoute',vRetailerCtrl.getSalesRoute);
vRouter.post('/getRetailerSummary',vRetailerCtrl.getRetailerSummary);
vRouter.get('/getRetailerAlert',vRetailerCtrl.getAllRetailerAlert);
// vRouter.post('/accountsReceivables',vAccCtrl.accountsReceivables);
// vRouter.post('/retailerSelf',vAccCtrl.retailerSelf);
vRouter.get('/testSync',vSchedCtrl.syncTableMaster);
//API BASED ON GUIDELINES
vRouter.get('/task',vRetailerCtrl.task);
vRouter.post('/retailerCallPreparation',vRetailerCtrl.retailerCallPreparation);
vRouter.post('/loadWallet',vRetailerCtrl.loadWallet);
示例2: constructor
constructor() {
this.router = express.Router();
this.router.get('/', this.index);
}
示例3: Router
import {Request, Response, Router} from "express";
const router: Router = Router();
import {IRoute} from "express-serve-static-core";
import {entityModel} from "../models/models";
import {checkObjectIDValidity, checkIfDataIsArray} from "../helpers/validation";
import {errorIDValidationMessages, errorApiMessages} from "../helpers/errorMessages";
const api: IRoute = router.route("/api/entity/:id");
api.get(async (req: Request, res: Response) => {
let id: string = req.params.id;
if (!checkObjectIDValidity(id)) {
res.status(400).json(errorIDValidationMessages.getMessage);
}
let obj: Object = await entityModel
.find({_id: id})
.exec()
.catch((e: Error) => {
res.status(400).send({ error: errorApiMessages.postMessage + e });
});
res.json(obj);
});
api.post(async (req: Request, res: Response) => {
// check data before saving also could do validation within function
let obj: Array<Object> = checkIfDataIsArray(req.body);
let dataRes: Object = await entityModel.insertMany(obj);
res.status(200).json(dataRes);
示例4: require
import * as express from 'express'
import * as _ from 'lodash'
import { data } from '../data-import/data-storage'
import { IGroup } from '../data-import/data-import'
import * as path from 'path';
import * as request from 'request';
var shipNameToImageId = require('../public/ship-name-to-image-id.json');
export let router = express.Router({ mergeParams: true });
var result: Array<IGroup> = JSON.parse(data);
router.get('/', (req: express.Request, res: express.Response) => {
let race = findRace(result, req);
let response = _.map(race.ships, (ship) => {
return {
name: ship.name,
group: ship.group,
race: ship.race
};
});
res.json(response);
});
router.get('/:shipId', (req: express.Request, res: express.Response) => {
let race = findRace(result, req);
res.send(_.find(race.ships, { name: req.params.shipId }));
});
示例5: getAuthorizationData
import * as express from 'express';
import {sendError, formatSend, getAuthorizationData} from '../core/web_util';
import {addressBookGroupService} from './address_book_group_service';
import {AddressBookGroup, ModelOptions} from '../../client/core/dto';
const router = express.Router();
router.post('/', (req, res) => {
const modelOptions: ModelOptions = {
authorization: getAuthorizationData(req),
copyAuthorizationData: 'createdBy'
};
addressBookGroupService.createOne(req.body, modelOptions)
.then((group: AddressBookGroup) => formatSend(res, group), (err) => sendError(res, err));
});
router.put('/:id', (req, res) => {
const modelOptions: ModelOptions = {
authorization: getAuthorizationData(req)
};
req.body._id = req.params.id;
addressBookGroupService.updateOne(req.body, modelOptions)
.then((group: AddressBookGroup) => formatSend(res, group), (err) => sendError(res, err));
});
router.delete('/:id', (req, res) => {
const modelOptions: ModelOptions = {
authorization: getAuthorizationData(req),
additionalData: {_id: req.params.id}
};
示例6: require
/// <reference path="../typings/tsd.d.ts"/>
import {Request, Response} from "express";
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req: Request, res: Response, next: Function) {
res.render('index', { title: 'Express' })
});
module.exports = router;
示例7: Router
import {Router} from 'express';
import {addPost,searchPost, searchPostArea, pushElasticSearch, getAll,
editPost,addView,getPostAllByUser}
from '../controller/postController';
import {addRate} from '../controller/rateController';
import {verifyToken} from '../libs/verifyToken';
const router: any = Router();
import { uploadPost as upload } from '../libs/uploads';
router.route('/post')
.post(upload, verifyToken, addPost)
.put(verifyToken, editPost)
.all((req: any, res: any, next: any) => {
res.sendStatus(404);
});
router.route('/elastichpush')
.get(pushElasticSearch)
.all((req: any, res: any, next: any) => {
res.sendStatus(404);
});
router.route('/search')
.get(searchPost)
.all((req: any, res: any, next: any) => {
res.sendStatus(404);
});
router.route('/limit/:limit/offset/:offset')
.get(getAll)
示例8: require
import * as express from 'express';
import * as bodyParser from 'body-parser';
var jwt = require('jsonwebtoken');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var localStrategyConfig = require('./strategies/local');
import * as User from './../../user/User';
var config = require('./config');
// CONFIG
localStrategyConfig();
const authRoutes: express.Router = express.Router();
// ROUTES
authRoutes.post('/', function(req: express.Request, res: express.Response, next) {
console.log(req.body)
if (req.body.type) {
switch (req.body.type) {
case 'password':
localAuthentication(req, res, next);
}
} else {
return res.status(401).send({
message: 'credentials not provided'
});
}
示例9:
import * as express from 'express'
import * as _ from 'lodash'
import {data} from '../data-import/data-storage'
import * as races from './races'
import {IGroup} from '../data-import/data-import'
export var router = express.Router({mergeParams: true});
router.get('/', (req:express.Request, res:express.Response)=>{
var result:Array<IGroup> = JSON.parse(data);
_.each(result, (group:IGroup)=>{
delete group.races;
})
res.json(result);
});
router.get('/:groupId', (req:express.Request, res:express.Response)=>{
var groups:Array<IGroup> = JSON.parse(data);
var group = _.find(groups, {name: req.params.groupId});
delete group.races;
res.send(group);
});
router.use('/:groupId/races', races.router);
示例10: createReqFiles
videosSortValidator,
videosUpdateValidator
} from '../../../middlewares'
import { TagModel } from '../../../models/video/tag'
import { VideoModel } from '../../../models/video/video'
import { VideoFileModel } from '../../../models/video/video-file'
import { abuseVideoRouter } from './abuse'
import { blacklistRouter } from './blacklist'
import { videoCommentRouter } from './comment'
import { rateVideoRouter } from './rate'
import { VideoFilter } from '../../../../shared/models/videos/video-query.type'
import { VideoSortField } from '../../../../client/src/app/shared/video/sort-field.type'
import { createReqFiles, isNSFWHidden } from '../../../helpers/express-utils'
import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update'
const videosRouter = express.Router()
const reqVideoFileAdd = createReqFiles(
[ 'videofile', 'thumbnailfile', 'previewfile' ],
Object.assign({}, VIDEO_MIMETYPE_EXT, IMAGE_MIMETYPE_EXT),
{
videofile: CONFIG.STORAGE.VIDEOS_DIR,
thumbnailfile: CONFIG.STORAGE.THUMBNAILS_DIR,
previewfile: CONFIG.STORAGE.PREVIEWS_DIR
}
)
const reqVideoFileUpdate = createReqFiles(
[ 'thumbnailfile', 'previewfile' ],
IMAGE_MIMETYPE_EXT,
{
thumbnailfile: CONFIG.STORAGE.THUMBNAILS_DIR,