當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。