本文整理匯總了TypeScript中express.Request.accepts方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Request.accepts方法的具體用法?TypeScript Request.accepts怎麽用?TypeScript Request.accepts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類express.Request
的用法示例。
在下文中一共展示了Request.accepts方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: default
export default (err: Error, req: Request, res: Response, next: NextFunction) => {
if (req.accepts('json')) {
res.json({
message: err.message
});
return;
}
next();
};
示例2: return
return (req: Request, res: Response, next: NextFunction) => {
const accepted = req.accepts(ACCEPT_HEADERS)
if (accepted === false || ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS.indexOf(accepted) === -1) {
return next()
}
logger.debug('ActivityPub request for %s.', req.url)
if (Array.isArray(fun) === true) {
return eachSeries(fun as RequestHandler[], (f, cb) => {
f(req, res, cb)
}, next)
}
return (fun as RequestHandler)(req, res, next)
}
示例3:
.get((req: Request, res: Response, next: NextFunction) => {
req.accepts('application/json');
console.log('hello');
});