本文整理匯總了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)
})