本文整理汇总了TypeScript中koa-compose.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: default
export default (app?: Koa) => {
const provided = !!app
const middlewares = [bodyParser(), router.routes(), router.allowedMethods()]
if (!app) {
app = new Koa()
app.keys = app.keys = (process.env.APP_KEYS || '').split(',')
middlewares.unshift(session({}, app))
}
if (provided) {
return middlewares
}
app.use(compose(middlewares))
app.listen(serverPort + 1, serverHost, () => {
debug('Router server is now running at %s:%s', serverHost, serverPort + 1)
})
}
示例2: k
export default function k(...middleware:AppMiddleware[] ): AppMiddleware {
return compose(middleware);
};
示例3: function
return async function (ctx: Context, next: Function) {
let oldValue = await _getValue(ctx, param);
if (oldValue == null) ctx.throw(500, `${Parameter[param]} has no value`);
let value = Object.assign({}, oldValue);
if (ctx.matched) {
if (param === Parameter.Params && ctx.matched.length) {
// Get the last match
let match = ctx.matched[ctx.matched.length - 1];
value = match.params(ctx.path, ctx.captures, {});
}
}
try {
debug(`validation '%s' on '%s': %j`, Parameter[param], ctx.originalUrl, value);
let invalid = await validator.validate(value);
if (invalid instanceof Error) {
throw invalid;
}
await _setValue(ctx, param, invalid);
} catch (e) {
debug('error while validating "%s" on "%s": %s', Parameter[param], ctx.originalUrl, e.message);
if (shouldThrow) {
ctx.throw(400, e.message);
}
// Set old value
await _setValue(ctx, param, null)
return next();
}
return await compose(success)(ctx, next);
}
示例4: switch
switch (parse.type) {
case 'number':
args[index] = Number(args[index])
break
case 'string':
args[index] = String(args[index])
break
case 'boolean':
args[index] = String(args[index]) === 'true'
break
}
})
// 调用实际的函数,处理业务逻辑
let results = controller.controller(...args)
ctx.body = results
})
}
)
routers.push(router.routes())
})
const app = new Koa()
app.use(bodyParse())
app.use(compose(routers))
app.listen(12306, () => console.log('server run as http://127.0.0.1:12306'))
示例5: koaCompose
export const compose = <ClientsT extends IOClients, StateT, CustomT>(middlewares: Array<RouteHandler<ClientsT, StateT, CustomT>>) =>
koaCompose(middlewares.map(timer))
示例6: compose
requireAuth(middleware: KoaMiddleware): KoaMiddleware {
return compose([auth(this.getUser), middleware]);
}
示例7: compress
middlewares.splice(
1,
0,
compress(),
publicStatic,
staticCache('dist/static', { maxAge: MAX_AGE }, files),
sessionMiddleware,
...startRouter(app),
)
files['/service-worker.js'].maxAge = 0
}
middlewares.push(
proxy('api.github.com/graphql', {
filter: ctx => ctx.url === '/graphql',
https: true,
proxyReqOptDecorator(req, ctx) {
req.headers.Authorization = `bearer ${ctx.session.token ||
process.env.GITHUB_TOKEN}`
return req
},
}),
)
app.use(compose(middlewares))
app.listen(serverPort, serverHost, () => {
debug('Server is now running at %s:%s', serverHost, serverPort)
})