本文整理汇总了TypeScript中koa.on函数的典型用法代码示例。如果您正苦于以下问题:TypeScript on函数的具体用法?TypeScript on怎么用?TypeScript on使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了on函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: beforeAll
beforeAll((done)=> {
jasmine.DEFAULT_TIMEOUT_INTERVAL=1000;
const Koa = require('koa');
const busboy = new KoaBusBoy({
limits: {
fields: 1,
fileSize: 1
}
});
const app = new Koa();
app.use(busboy);
app.use((ctx: any)=> {
if (ctx.formData) {
ctx.body = ctx.formData;
} else {
ctx.body = 'hello world';
}
});
app.on('error', (error: Error, ctx: any)=> {
ctx.status = 400;
ctx.body = error.message;
});
app.listen(3001, ()=> {
done();
});
});
开发者ID:sqram,项目名称:koa-async-body,代码行数:31,代码来源:limit.spec.ts
示例2: Koa
const koa = new Koa();
const router = new Router();
const JWT_SECRET = "" + config.get("UI_JWT_SECRET");
const JWT_COOKIE = "genieacs-ui-jwt";
function getPermissionSets(ctx): PermissionSet[] {
const allPermissions = localCache.getPermissions(ctx.state.configSnapshot);
const permissionSets = ctx.state.user.roles.map(role =>
Object.values(allPermissions[role] || {})
);
return permissionSets;
}
koa.on("error", async err => {
throw err;
});
koa.use(async (ctx, next) => {
const configSnapshot = await localCache.getCurrentSnapshot();
ctx.state.configSnapshot = configSnapshot;
return next();
});
koa.use(
koaJwt({
secret: JWT_SECRET,
passthrough: true,
cookie: JWT_COOKIE
})
);
开发者ID:zaidka,项目名称:genieacs,代码行数:31,代码来源:ui.ts
示例3: next
app
.use(koaBodyparser())
.use(async (ctx: Koa.Context, next: any) => {
try {
await next();
} catch (err) {
ctx.status = err.status || 500;
ctx.body = err.message;
app.emit("error", err, ctx);
}
})
.use(github)
.use(slackMiddleware);
app.on("error", err => {
log(err);
});
app.on("ready", msg => {
log(msg);
});
if (!module.parent) {
app.listen(port, () =>
app.emit("ready", chalk.black.bgGreen.bold(`Listening on port ${port}`))
);
}
export default app;
开发者ID:ft-interactive,项目名称:ft-ig-github-project-manager,代码行数:29,代码来源:index.ts
示例4: next
viewPath: viewPath,
noCache: Config.isDevEnv,
pretty: Config.isDevEnv,
locals: {
iconsDir: '/dist/public/images/icons'
}
});
app.use(async (ctx, next) => {
try {
await next();
} catch (error) {
if (error instanceof MongoError) {
log('Got unhandled mongo error, checking connection.');
rebuildConnectionAsync();
} else {
log(`Error on middleware\n${error}`);
}
ctx.body = { message: error.message };
ctx.status = error.status || 500;
}
});
app.use(router.routes())
.use(router.allowedMethods());
app.on('error', (err: any, ctx: any) => {
console.error('server error', err, ctx);
});
export default app;
开发者ID:lleitep3,项目名称:transempregos-portal,代码行数:31,代码来源:app.ts
示例5: switch
switch (environment) {
case 'build':
//TODO: implement build environment server
break;
default:
console.log('*** DEV ***');
console.log('rootDir: ' + rootDir);
app.use(convert(serve(path.join(rootDir, './src/client'))));
app.use(convert(serve(path.join(rootDir, './'), { hidden: true })));
router.get('/*', function *(ctx: KoaRouter.IRouterContext, next: any) {
this.body = yield fs.readFile(path.join(rootDir, './src/client/index.html'), 'utf-8');
});
break;
}
app.use(convert(router.routes()));
app.on('error', (err: Error) => {
console.log(err);
console.log('Koa server error occurred.');
});
if (!module.parent) {
app.listen(port, function() {
console.log(`Koa server listening on port ${port}...`);
});
}
开发者ID:JuHwon,项目名称:ironcrux,代码行数:29,代码来源:app.ts
注:本文中的koa.on函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论