本文整理匯總了TypeScript中express.Response.header方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Response.header方法的具體用法?TypeScript Response.header怎麽用?TypeScript Response.header使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類express.Response
的用法示例。
在下文中一共展示了Response.header方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: next
router.use((req: Request, res: Response, next: any)=> {
util.log(util.format("Request to: %s:%s -- Params:%s",
req.url, req.method, JSON.stringify(req.body)));
res.setHeader('Access-Control-Allow-Credentials', "true");
res.header("Access-Control-Allow-Origin", req.header("Origin"));
res.header("Access-Control-Allow-Methods", "GET,POST,PUT,HEAD,DELETE,OPTIONS");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
if ('OPTIONS' == req.method) {
res.sendStatus(200);
}
else {
next();
}
});
示例2: injectGalleryVersion
/**
* This version data is mainly used on the client side to invalidate the cache
* @param req
* @param res
* @param next
*/
public static async injectGalleryVersion(req: Request, res: Response, next: NextFunction) {
try {
res.header(CostumHeaders.dataVersion, await ObjectManagers.getInstance().VersionManager.getDataVersion());
next();
} catch (err) {
return next(new ErrorDTO(ErrorCodes.GENERAL_ERROR, 'Can not get data version', err.toString()));
}
}
示例3: next
app.use((req: Request, res: Response, next: NextFunction) => {
if (config.app.forceHttps === 'enabled') {
if (!req.secure) {
return res.redirect('https://' + req.hostname + ':' + config.app.httpsPort + req.originalUrl);
}
res.setHeader('Strict-Transport-Security', 'max-age=31536000');
}
if (req.method !== 'OPTIONS' && req.header('Accept') !== 'application/json' && req.header('Content-Type') === 'application/json') {
return res.status(406).json({
error: 'Unsupported "Accept" header'
});
}
res.setHeader('X-Content-Type-Options', 'nosniff');
res.setHeader('X-Frame-Options', 'deny');
res.setHeader('Content-Security-Policy', 'default-src \'none\'');
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Authorization, Origin, X-Requested-With, Content-Type, Accept');
return next();
});
示例4: next
app.use(function(req:Request, res:Response, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
示例5: nocache
public nocache (req:Request, res:Response, next:NextFunction){
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate')
res.header('Expires', '-1')
res.header('Pragma', 'no-cache')
next()
}