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


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

本文整理汇总了TypeScript中koa-compress.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了default函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: function

module.exports = function(app) {
  app.use(
    cors(
      {
        maxAge: 3600, //default value is null, 3600 seconds is too big for a request and response result to be cached
        credentials: true,
        headers: 'Access-Control-Allow-Origin, Access-Control-Expose-Headers, Origin, X-Requested-With, Content-Type, Accept, Authorization',
        methods: 'GET, HEAD, OPTIONS, PUT, POST, DELETE'
      }
    )
  );

  app.use(
    function* (next) {
      this.req.connection.setTimeout(0);  //removes the default timeout of connection i.e. 2 minutes
      this.req.connection.setNoDelay(true); /**will set delay to false and data would be fired
                                          immediately after calling socket.write
                                            */
      yield next;
    }
  );

  app.use(
    compress() /** used for compressing the data in request and response
                   options : filter @default compresser ; or "".test(content-type) #it is for filtering wether content
                                                                                   #is compressable or not
                           : threshold @default 1024 bytes ; or setable according to requirement
                  */
  );

  let pubRouter = router();   /**  koa-router function gets encapsulated in the variables pubRouter,
                                   secRouter, adminRouter */
  let secRouter = router();
  let adminRouter = router();

  fs.readdirSync('./server/controller').forEach(function(file) {
    if (!file.endsWith('.js'))
      return;
    let controller = require('../controller/' + file);
    if (controller.initAdmin)
      controller.initAdmin(adminRouter); //Each controller gets now instantiated by passing the router function
    if (controller.initPub)                //the router function @stacks a key value (see Layer.js for exact details of arrays) pair
      controller.initPub(pubRouter);    // for path and function and loads all the functions in there
    if (controller.initSecured)           //specific router(i.e. pub,admin,sec) @stacks
      controller.initSecured(secRouter);
  });

  app.use(
    parse(
      {
        multipart: true, /** HTTP multipart request (data) is concatenated if flagged as true*/
        formidable: {
          uploadDir: config.appConfig.app.uploads  //files that are non parsable like images are uploaded to the directory
        }
      }
    )
  );

  app.use(
    function* (next) {
      this.log = logger;
      logger.debug('Request : ', this.request); /**  Koa Logging request recieved */
      try {
        yield next;
      } catch (err) {
        logger.error('Error : ', err);
        this.status = err.status || 500;
        this.body = { err: err.message };
        this.app.emit('error', err, this);
      }
    }
  );

  app.use(
    pubRouter.routes()  /**  Returns a route matching this.path */
  );

  app.use(
    function* (next) {
      if (pubRouter.match(this.path, this.method).pathAndMethod.length) {
        return; /**  if the route matches then th function gets executed and response returns */
      }
      yield next;
    }
  );

  app.use(

    /**
        Using koa-jwt
        usage :
        jwt({<options>})

        options : key value pairs
        secret : <string/or a encrypted key buffer>
        key : pay load identifier post decryption of Token <this.state.key>
        algorithm : define encryptiona and decryption algorithm
                    default algo is  <[HS256,HS384,HS512]>
     */
    koajwt({ secret: config.systemConfig.app.privateKey, key: "wbuser" })
//.........这里部分代码省略.........
开发者ID:girishgupta211,项目名称:LAAS_Server,代码行数:101,代码来源:koa.ts

示例2: koaCompress

      <title>GenieACS</title>
      <link rel="shortcut icon" type="image/png" href="favicon.png" />
      <link rel="stylesheet" href="app.css">
    </head>
    <body>
      <script>
        window.clientConfig = ${JSON.stringify({
          ui: localCache.getUiConfig(ctx.state.configSnapshot)
        })};
        window.username = ${JSON.stringify(
          ctx.state.user ? ctx.state.user.username : ""
        )};
        window.permissionSets = ${JSON.stringify(permissionSets)};
      </script>
      <script src="app.js"></script>
    </body>
  </html>
  `;
});

koa.use(
  koaCompress({
    flush: Z_SYNC_FLUSH
  })
);

koa.use(router.routes());
koa.use(koaStatic("./public"));

export const listener = koa.callback();
开发者ID:zaidka,项目名称:genieacs,代码行数:30,代码来源:ui.ts

示例3: Koa

const logger = new winston.Logger({
  transports: [
    new winston.transports.Console({
      json: false,
      timestamp: true,
      level: config.log.level
    })
  ]
});

logger.verbose('Starting with configuration', config);

const app = new Koa();

app.use(compress());
app.use(cors);
app.use(logging(logger));
app.use(bodyParser());
app.use(router.routes());

const server = http.createServer(app.callback());
server.setTimeout(constants.socketLifetime);

db.connect(config.db.url, config.db.name, config.db.options)
  .then(() => server.listen(config.app.port as number, config.app.ip))
  .then(() => logger.verbose(`Listening on port ${config.app.port}`))
  .catch((e: any) => {
    logger.error(e);
    process.exit(1);
  });
开发者ID:easygenerator,项目名称:lrs,代码行数:30,代码来源:app.ts

示例4: next

var manifest;

fileReload(
    path.resolve(__dirname, '../../../webpack-assets.json'),
    content => manifest = JSON.parse(content)
);

var serveStaticOptions = {
    maxAge: 30,
    buffer: true
};
serveStaticOptions = null;

const app: Koa = new Koa();
app.use(compress({
    flush: zlib.Z_SYNC_FLUSH
}));
app.use((ctx: Koa.Context, next)=> {
    return next().then(() => {
        ctx.set('Cache-Control', 'max-age=31536000'); // 1 year
    });
    // ctx.set('Cache-Control', 'no-cache');
});
app.use(serveStatic('.www', serveStaticOptions));

var mvc = new Mvc();
mvc.registerAreas(__dirname, ['/admin', '/home'], {
    views: {
        extension: 'pug',
        engine: 'pug',
        templateOptions: {
开发者ID:pbalaga,项目名称:craftdb,代码行数:31,代码来源:app.ts

示例5: createRenderer

} else {
  renderer = createRenderer(
    runtimeRequire(resolve('dist/vue-ssr-server-bundle.json')),
    {
      clientManifest: runtimeRequire(
        resolve('dist/vue-ssr-client-manifest.json'),
      ),
    },
  )

  const files: staticCache.Files = {}

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


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