本文整理汇总了TypeScript中koa.Context.set方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Context.set方法的具体用法?TypeScript Context.set怎么用?TypeScript Context.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类koa.Context
的用法示例。
在下文中一共展示了Context.set方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
export default async (ctx: Context, next: Function) => {
ctx.set('Access-Control-Allow-Origin', '*');
ctx.set('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
ctx.set(
'Access-Control-Allow-Headers',
// tslint:disable-next-line:max-line-length
'X-Experience-API-Version,X-Access-Token,X-Id-Token,X-Entity-Id,X-Entity-Type,Accept,Authorization,Content-Type,If-Match,If-None-Match,Cache-Control,Pragma,Expires'
);
if (ctx.method === 'OPTIONS') {
ctx.status = 200;
} else {
await next();
}
};
示例2: default
export default (ctx: Context, next: () => Promise<any>) => {
if ('/favicon.ico' !== ctx.path) {
return next();
}
if ('GET' !== ctx.method && 'HEAD' !== ctx.method) {
ctx.set('Allow', 'GET, HEAD, OPTIONS');
ctx.status = ctx.method === 'OPTIONS' ? 200 : 405;
}
else {
ctx.set('Cache-Control', CACHE);
ctx.type = 'image/x-icon';
ctx.body = ICON;
}
};
示例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);
};
示例4: async
getCsv: async (ctx: Context) => {
const options = getQueryOptions(ctx);
if (options.isCourseResult) {
const csvResult = await csvGenerator.generateCourseCsv(options.criteria, options.cultures, options.timezone);
ctx.set('X-Entity-Title', csvResult.entityTitle);
ctx.body = csvResult.stream;
} else {
ctx.body = await csvGenerator.generateLearningPathCsv(options.criteria, options.cultures, options.timezone);
}
ctx.type = 'text/csv';
ctx.status = 200;
},
示例5: forbid
/**
*
* @param ctx
*/
function forbid(ctx: Context) {
ctx.set('WWW-Authenticate', 'Basic');
ctx.status = 401;
}