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