當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Request.get方法代碼示例

本文整理匯總了TypeScript中express.Request.get方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Request.get方法的具體用法?TypeScript Request.get怎麽用?TypeScript Request.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在express.Request的用法示例。


在下文中一共展示了Request.get方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getUser

function getUser(request: Request): Result<User> {
    let result: Result<User> = new ResultBasic<User>();
    let username = request.get('username');
    let password = request.get('password');
    userService.getUserByUserame(username)
        .onSuccess((user: User) => {
            result.success(user);
        })
        .onError((err: any) => {
            result.error(err);
        });
    return result;
}
開發者ID:andi-git,項目名稱:nodejs-test,代碼行數:13,代碼來源:app.ts

示例2: return

  return (req: Request, res: Response, next: Function) : void => {
    let requestEnd = res.end;
    let requestedUrl: string = url.parse(req.originalUrl);
    let startTime: Date  = new Date();
    let userAgent: string = req.get('User-Agent');

    res.end = (chunk?: any, encoding?: any) : void => {
      let time: Date = new Date();
      let data = {
        'statusCode': res.statusCode,
        'method': req.method,
        'responseTime': time.getTime() - startTime.getTime(),
        'url': req.originalUrl,
        requestedUrl,
        'ip': req.headers['x-forwarded-for'] || req.ip,
        'userAgent': userAgent,
        'language': req.query.lang || lang
      };

      res.end = requestEnd;
      res.end(chunk, encoding);

      logr.info('', data);
    };

    next();
  };
開發者ID:melxx001,項目名稱:simple-nodejs-typescript-starter,代碼行數:27,代碼來源:index.ts

示例3: async

router.post('/', async (req: Request, res: Response, next: NextFunction) => {
    let label = req.body.label || '';
    label = label.replace(/[^a-zA-Z0-9-\.\/ ]/, '');

    if (label === '') {
        label = useragent.parse(req.get('user-agent')).toString();
    }

    const persist = [true, '1', 'true'].indexOf(req.body.persist) > -1;

    const token = new Token(label, persist);

    await db.addTokens(req.user, [token]);

    const cookieOptions: CookieOptions = {
        path: req.app.locals.config.get('NOTIFIER_BASE_URL'),
    };

    if (token.persist) {
        cookieOptions.expires = new Date(Date.now() + (86400000 * 30));
    }

    res.cookie('token', `${token.key},${token.value}`, cookieOptions);

    res.format({
        'application/json': () => res.json({
            key: token.key,
            value: token.value,
        }),
        'default': () => res.status(406).send('Not Acceptable'),
        'text/plain': () => res.send(`${token.key},${token.value}`),
    });

    next();
});
開發者ID:lovett,項目名稱:notifier,代碼行數:35,代碼來源:auth.ts

示例4: url

 public async url(req: Request, res: Response) {
   const url = req.get('host') + req.originalUrl;
   const settings = this.settings.generator.urls.find((o) => o.url.endsWith(url));
   if (settings) {
     if (!(await this.isEnabled())) {
       return res.status(412).send({ error: 'Highlights system is disabled' });
     } else {
       if (!(await global.cache.isOnline())) {
         return res.status(412).send({ error: 'Stream is offline' });
       } else {
         if (settings.clip) {
           const cid = await global.api.createClip({ hasDelay: false });
           if (!cid) { // Something went wrong
             return res.status(403).send({ error: 'Clip was not created!'});
           }
         }
         if (settings.highlight) {
           this.main({ parameters: '', sender: null });
         }
         return res.status(200).send({ ok: true });
       }
     }
   } else {
     return res.status(404).send({ error: 'Unknown highlights link' });
   }
 }
開發者ID:sogehige,項目名稱:SogeBot,代碼行數:26,代碼來源:highlights.ts

示例5: verifyUrl

    verifyUrl(req: Request, addressReader?: Types.AddressReader): Types.VerifyResult {
        const url = req.protocol+'://'+req.get('host')+req.url;

        if( url.length < 33  ||  !this.verifyString( url.substring(0, url.length-32), url.substr(-32) ) ) {
            return Types.VerifyResult.blackholed;
        }

        // get signed data
        let lastAmpPos = url.lastIndexOf('&signed=');
        if(lastAmpPos == -1) {
            lastAmpPos = url.lastIndexOf('?signed=');
        }
        if(lastAmpPos == -1) {
            return Types.VerifyResult.blackholed;
        }
        const data = querystring.parse( url.substring(lastAmpPos+8, url.length-33), ';', ':');
        req.url = url.substr(0, lastAmpPos);

        // check additional conditions
        if(data.a  &&  addressReader  &&  data.a != addressReader(req)) {
            return Types.VerifyResult.blackholed;
        }
        if(data.m  &&  data.m.indexOf(req.method) == -1) {
            return Types.VerifyResult.blackholed;
        }
        if(data.e  &&  data.e < Math.ceil(+new Date()/1000)) {
            return Types.VerifyResult.expired;
        }
        return Types.VerifyResult.ok;
    }
開發者ID:smbwain,項目名稱:signed,代碼行數:30,代碼來源:index.ts

示例6: getRequestUrl

export function getRequestUrl(req: Request) {
    return url.format({
        protocol: req.protocol,
        host: req.get('host'),
        pathname: req.path,
        search: querystring.stringify(req.query)
    });
}
開發者ID:itsuryev,項目名稱:tp-oauth-server,代碼行數:8,代碼來源:expressUtils.ts

示例7: getRawValue

 protected getRawValue(request: Request): any {
     const cookies = request.get('cookie');
     if (!cookies) {
         return undefined;
     }
     const cookie = cookies
         .split(';')
         .map(o => new CookieHelper(o.trim()))
         .filter(o => o.name === this.name)[0];
     return cookie ? cookie.value : undefined;
 }
開發者ID:smartive,項目名稱:giuseppe,代碼行數:11,代碼來源:Cookie.ts

示例8: return

 return (req: Request, res: Response, next: RequestHandler) => {
     res.set('OData-Version', '4.0');
     
     var data = this.document(format)
     if (!data['@odata.context']) {
         var url = req.protocol + '://' + req.get('host') + req.originalUrl.split("?").shift();
         if(url.slice(-1) !== '/') url += '/'
         data['@odata.context'] = url + '$metadata';
     }
     
     res.json(data);
 };
開發者ID:jaystack,項目名稱:odata-v4-service-document,代碼行數:12,代碼來源:serviceDocument.ts

示例9: renderWithClientToken

function renderWithClientToken(template: string, req: Request, res: Response) {
  const token = shortid.generate();
  db.saveToken({
    date: new Date(),
    token,
    ip: req.ip,
    userAgent: req.get('User-Agent')
  });
  res.render(template, {
    clientToken: token,
    layout: false,
  });
}
開發者ID:shybyte,項目名稱:wahlomat,代碼行數:13,代碼來源:routes.ts

示例10: index

  index(req: Request, res: Response ) {
    const originUrl = req.protocol && req.get('host') ? req.protocol + '://' + req.get('host') : 'http://localhost:3000';
    const baseRef: string =  req.baseUrl && req.baseUrl !== '' ? req.baseUrl : '/';

    const expressConfig : ExpressEngineConfig = {
      req,
      res,
      ngModule: MainModule,
      originUrl: originUrl,
      baseUrl: baseRef,
      requestUrl: req.url || baseRef,
      preboot: false
    };

    res.render('index', expressConfig);
  }
開發者ID:Lumenss,項目名稱:testing-app,代碼行數:16,代碼來源:ViewController.ts


注:本文中的express.Request.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。