本文整理汇总了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()
}