当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Request.header方法代码示例

本文整理汇总了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();
});
开发者ID:Norestlabs-Mariya,项目名称:backend-ico-dashboard,代码行数:12,代码来源:app.ts

示例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()
    });
});
开发者ID:bernardius,项目名称:expressts,代码行数:14,代码来源:users.ts

示例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');
   }
}
开发者ID:Trail-Image,项目名称:blog,代码行数:16,代码来源:require-ssl.ts

示例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);
}
开发者ID:brechtbilliet,项目名称:WineCellarBackend,代码行数:8,代码来源:auth.ts

示例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;
  }
开发者ID:iamchairs,项目名称:demo-authorization-decorators,代码行数:13,代码来源:authorize.service.ts

示例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();
   }
 });
开发者ID:twicepixels,项目名称:tp-main-api,代码行数:14,代码来源:app.router.ts

示例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);
 }
开发者ID:MaxxtonGroup,项目名称:microdocs,代码行数:14,代码来源:route.ts

示例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();
        }
    })
}
开发者ID:szemurkaloz,项目名称:typescriptdemo,代码行数:15,代码来源:authMiddlware.ts

示例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) => {
开发者ID:linkFly6,项目名称:Said,代码行数:18,代码来源:backend.ts

示例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();
  }
}
开发者ID:Norestlabs-Mariya,项目名称:backend-ico-dashboard,代码行数:40,代码来源:request.validation.ts


注:本文中的express.Request.header方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。