本文整理汇总了TypeScript中express.Request.header方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Request.header方法的具体用法?TypeScript Request.header怎么用?TypeScript Request.header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类express.Request
的用法示例。
在下文中一共展示了Request.header方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: next
app.post('*', (req: Request, res: Response, next: NextFunction) => {
if (
!req.header('Content-Type') ||
(req.header('Content-Type') !== 'application/json' && !req.header('Content-Type').includes('application/x-www-form-urlencoded'))
) {
return res.status(406).json({
error: 'Unsupported "Content-Type"'
});
}
return next();
});
示例2: function
router.get('/', function (req:Request, res:Response, next:NextFunction) {
var userRequest : getUsersRequest = {
first:req.header('first'),
last:req.header('last'),
email:req.header('email'),
city:req.header('city'),
state:req.header('first')
};
userController.getUsers(userRequest).then(function (users) {
res.status(200).json(users).end();
}, function (err) {
res.status(300).json(err).end()
});
});
示例3: requireSSL
export function requireSSL(req: Request, res: Response, next: NextFunction) {
if (
req.secure ||
req.header(Header.ForwardedProtocol).toLowerCase() == protocol
) {
// already secure
next();
} else if (req.method == 'GET' || req.method == 'HEAD') {
res.redirect(
HttpStatus.TempRedirect,
protocol + '://' + req.header(Header.Host) + req.originalUrl
);
} else {
res.status(HttpStatus.Forbidden).send('Data must be transmitted securely');
}
}
示例4: handleAuth
export function handleAuth(req: Request, res: Response): string {
let token: string = req.header("Authorization").replace("Bearer ", "");
if (!validate(token)) {
res.status(400).send({error: "UNAUTHORIZED"});
return;
}
return getUserIdFromToken(token);
}
示例5: getRequestUser
public static getRequestUser(req: Request) {
let auth = req.header('Authorization');
// Check if user is authorized.
// Return user object
// Otherwise, return null
if(auth === 'my authorization method') {
return new UserModel();
}
return null;
}
示例6: 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();
}
});
示例7: getHandler
public getHandler(req: Request):BaseResponseHandler{
var exportType = req.query.export;
if(exportType == undefined){
exportType = req.header('export');
if(exportType == undefined){
exportType = 'default';
}
}
var response:new (injection:Injection)=>BaseResponseHandler = responses[exportType.toLowerCase()];
if(response == undefined){
return new TemplateResponseHandler(this.injection, exportType.toLowerCase());
}
return new response(this.injection);
}
示例8: authMiddlware
export function authMiddlware (req:Request, res: Response, next: Function){
Session.findOne({sid: req.header('Authorization')})
.populate('user')
.exec(function (err, foundsession) {
if (foundsession) {
req.user =foundsession.user;
req['isAuthenticated'] = true;
return next();
}else{
req['isAuthenticated'] = false;
req.user = null;
return next();
}
})
}
示例9: Promise
promise.then((token: string) => {
// 如果是通过 form-data 上传的数据,则通过 multer 取 req.body 的数据
if (~req.header('content-type').indexOf('multipart/form-data')) {
return new Promise(resolve => {
upload(req, res, (err: any) => {
if (err) {
log.error('formdata.error', err)
resolve(null)
return
}
log.info('formdata.call', req.body)
params = req.body
resolve(token || req.body.token)
})
})
}
return token
}).then((token: string | null) => {
示例10: onlyJumioIp
export function onlyJumioIp(req: Request, res: Response, next: NextFunction) {
const jumioIps = [
'184.106.91.66',
'184.106.91.67',
'104.130.61.196',
'146.20.77.156',
'34.202.241.227',
'34.226.103.119',
'34.226.254.127',
'52.53.95.123',
'52.52.51.178',
'54.67.101.173',
'162.13.228.132',
'162.13.228.134',
'162.13.229.103',
'162.13.229.104',
'34.253.41.236',
'52.209.180.134',
'52.48.0.25',
'35.157.27.193',
'52.57.194.92',
'52.58.113.86'
];
let ip = req.header('cf-connecting-ip') || req.ip;
/*
Check if IP has ipv6 prefix and remove it.
See: https://stackoverflow.com/questions/29411551/express-js-req-ip-is-returning-ffff127-0-0-1
*/
if (ip.substr(0, 7) === '::ffff:') {
ip = ip.substr(7);
}
if (jumioIps.indexOf(ip) === -1) {
return res.status(403).send();
} else {
return next();
}
}