当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript koa-compose.default函数代码示例

本文整理汇总了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)
  })
}
开发者ID:JounQin,项目名称:blog,代码行数:21,代码来源:index.ts

示例2: k

export default function k(...middleware:AppMiddleware[] ):  AppMiddleware {
    return compose(middleware);
};
开发者ID:D10221,项目名称:kua,代码行数:3,代码来源:kompose.ts

示例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);

    }
开发者ID:kildevaeld,项目名称:willburg,代码行数:43,代码来源:index.ts

示例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'))
开发者ID:Jiasm,项目名称:notebook,代码行数:30,代码来源:index.ts

示例5: koaCompose

export const compose = <ClientsT extends IOClients, StateT, CustomT>(middlewares: Array<RouteHandler<ClientsT, StateT, CustomT>>) =>
  koaCompose(middlewares.map(timer))
开发者ID:vtex,项目名称:apps-client-node,代码行数:2,代码来源:compose.ts

示例6: compose

 requireAuth(middleware: KoaMiddleware): KoaMiddleware {       
     return compose([auth(this.getUser), middleware]);
 }
开发者ID:D10221,项目名称:koa-tiny-acl,代码行数:3,代码来源:tests.ts

示例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)
})
开发者ID:JounQin,项目名称:blog,代码行数:30,代码来源:index.ts


注:本文中的koa-compose.default函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。