本文整理匯總了TypeScript中restify.Next.default方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Next.default方法的具體用法?TypeScript Next.default怎麽用?TypeScript Next.default使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類restify.Next
的用法示例。
在下文中一共展示了Next.default方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
return function (req:Request, res:Response, next:Next) {
var auth = (req as {authorization?:IAuthorization}).authorization;
if (auth && authBasic(auth.basic)) {
return next();
} else {
return next(new NotAuthorizedError());
}
}
示例2: getSingle
export function getSingle(req: Request, res: Response, next: Next): void {
const id = parseInt(req.params.id);
if (id) {
const customer = customers.find(c => c.id === id);
if (customer) {
res.send(customer);
next();
} else {
next(new NotFoundError());
}
} else {
next(new BadRequestError('Parameter id must be a number'));
}
}
示例3: deleteSingle
export function deleteSingle(req: Request, res: Response, next: Next): void {
const id = parseInt(req.params.id);
if (id) {
const customerIndex = customers.findIndex(c => c.id === id);
if (customerIndex !== (-1)) {
customers.splice(customerIndex, 1);
res.send(NO_CONTENT);
next();
} else {
next(new NotFoundError());
}
} else {
next(new BadRequestError('Parameter id must be a number'));
}
}
示例4: post
export function post(req: Request, res: Response, next: Next): void {
if (!req.body.id || !req.body.firstName || !req.body.lastName) {
next(new BadRequestError('Missing mandatory member(s)'));
} else {
const newCustomerId = parseInt(req.body.id);
if (!newCustomerId) {
next(new BadRequestError('ID has to be a numeric value'));
} else {
const newCustomer: ICustomer = { id: newCustomerId,
firstName: req.body.firstName, lastName: req.body.lastName };
customers.push(newCustomer);
res.send(CREATED, newCustomer, {Location: `${req.path()}/${req.body.id}`});
}
}
}
示例5: getAll
export function getAll(req: Request, res: Response, next: Next): void {
res.send(customers);
next();
}