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


TypeScript Context.get方法代碼示例

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


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

示例1: async

export default async (ctx: Context, next: Function) => {
  const apiKey = ctx.get('X-API-Key');

  if (apiKey === config.appApiKey) {
    await next();
  } else {
    ctx.body = "Access denied. Invalid 'X-API-Key' header was supplied";
    ctx.status = 403;
  }
};
開發者ID:easygenerator,項目名稱:lrs,代碼行數:10,代碼來源:verifyAppApiKey.ts

示例2: async

  return async (ctx: Context, next) => {
    const startTime = new Date().getTime();
    const date = new Date().toISOString();

    await next();

    const responseTime = new Date().getTime() - startTime;

    logger.info({
      date,
      status: ctx.status,
      remoteAddress: ctx.ip,
      method: ctx.method,
      url: ctx.url,
      referrer: ctx.get('Referrer'),
      userAgent: ctx.get('user-agent'),
      responseTime,
    });
  };
開發者ID:Canner,項目名稱:canner,代碼行數:19,代碼來源:loggerMiddleware.ts

示例3: async

export default async (ctx: Context, next: Function) => {
  const header = 'X-Experience-API-Version';
  if (ctx.get(header) && ctx.get(header).substring(0, 3) === config.xApiVersion.substring(0, 3)) {
    await next();
  } else {
    ctx.body = "Invalid 'X-Experience-API-Version' header was supplied";
    ctx.status = 400;
  }
  ctx.set(header, config.xApiVersion);
};
開發者ID:easygenerator,項目名稱:lrs,代碼行數:10,代碼來源:verifyXapiVersion.ts

示例4: async

export default async (ctx: Context, next: Function) => {
  const idToken = ctx.get('X-Id-Token');
  const entityId = ctx.get('X-Entity-Id');
  const entityType = ctx.get('X-Entity-Type');
  if (!idToken || !entityId || !entityType) {
    return reject(ctx);
  }
  try {
    const token: any = decodeJWT(idToken);
    const issuer = token.iss;
    const identityId = token.unique_name;
    if (!isKnownIssuer(issuer)) {
      return reject(ctx);
    }
    let path = config.permissionsEndpoint.coursePath;
    let data: any = { courseId: entityId };
    if (entityType === constants.entityTypes.learningPath) {
      path = config.permissionsEndpoint.learningPathPath;
      data = { learningpathId: entityId };
    }
    let response;
    if (issuer === 'localhost') {
      response = { body: { data: constants.accessTypes.academy } };
    } else {
      response = await httpRequestSender.post(`https://${issuer}${path}`, data, {
        Authorization: `Bearer ${idToken}`
      });
      if (!response || !response.body || response.statusCode !== 200) {
        return reject(ctx);
      }
    }
    ctx.entityId = entityId;
    ctx.entityType = entityType;
    ctx.identityId = identityId;
    ctx.identityAccessLevel = response.body.data;
  } catch (e) {
    return reject(ctx);
  }
  await next();
};
開發者ID:easygenerator,項目名稱:lrs,代碼行數:40,代碼來源:idTokenAuth.ts

示例5: async

export default async (ctx: Context, next: Function) => {
  const accessToken = ctx.get('X-Access-Token');
  if (accessToken) {
    const info = await httpRequestSender.get(`https://${config.tokensUri}/${accessToken}`, {
      'X-Api-Key': config.tokensApiKey
    });

    if (!info || info.revoked || !info.entityId || !info.entityType || info.scopes.indexOf('read') === -1 || !info.createdBy) {
      return reject(ctx);
    }

    ctx.entityId = info.entityId;
    ctx.entityType = info.entityType;
    ctx.identityId = info.createdBy;
    await next();
    return;
  }

  await idTokenAuth(ctx, next);
};
開發者ID:easygenerator,項目名稱:lrs,代碼行數:20,代碼來源:auth.ts


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