當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。