How to use koa-etag - 10 common examples

To help you get started, we’ve selected a few koa-etag examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lanjingling0510 / blog / react-isomorphic-hot-example / src / server / middleware.js View on Github external
// 触发 koa 统一错误事件,可以打印出详细的错误堆栈 log
                app.emit('error', e, ctx);
            }
        }
    });


    app.use(conditional());

    // cache and static resource
    app.use(koaStatic('static', {
        maxage: 1000 * 60 * 60 * 24 * 30,
    }));

    // etag middleware
    app.use(koaEtag());

    // template ejs
    app.use(views(templatePath, { extension: 'ejs' }));

    // router dispatcher
    app.use(controller.routes());
    // 404
    app.use(async() => {
        throw {status: 404};
    });
}
github electerm / electerm / src / server / init / app-init.js View on Github external
export default function init() {

  // global middlewares
  app.keys = ['sugo:' + env]

  app.use(compress({
    threshold: 2048,
    flush: require('zlib').Z_SYNC_FLUSH
  }))

  //get
  app.use(conditional())

  // add etags
  app.use(etag())

  // //static
  // app.use(async (ctx, next) => {
  //   ctx.set('Cache-Control', 'private, no-cache, no-store, must-revalidate')
  //   ctx.set('Expires', '-1')
  //   ctx.set('Pragma', 'no-cache')
  //   await next()
  // })
  app.use(mount('/_bc', serve(cwd + '/node_modules', staticOption())))

  // body
  app.use(bodyparser)

  if (env === 'development') {
    app.use(logger())
  }
github acdlite / flummox-isomorphic-demo / src / server / routes / middleware.js View on Github external
this.body = error.message;
      this.app.emit('error', error, this);
    }
  });

  // gzip compression
  app.use(gzip());

  // Conditional GET
  app.use(conditional());

  // Freshness testing
  app.use(fresh());

  // etags
  app.use(etag());

  // Serve static assets from `public` directory
  app.use(serve('public'));

  // Add jade rendering
  app.use(views(path.join(process.cwd(), 'views'), {
    cache: true,
    default: 'jade',
  }));

  app.use(router(app));
}
github hung-phan / koa-react-isomorphic / app / server / infrastructure / middlewares / index.js View on Github external
export const initialLayer = (app: Object) =>
  app
    .use(bodyParser())
    .use(conditionalGet())
    .use(etag()); // https://github.com/koajs/bodyparser // https://github.com/koajs/conditional-get // https://github.com/koajs/etag
github moovel / teamchatviz / server / index.js View on Github external
apiApp.use(passport.initialize());
apiApp.use(passport.session());
apiApp.use(demoAuth);
apiApp.use(api.routes());
apiApp.use(api.allowedMethods());

const app = new Koa();
app.keys = [ config.sessionSecret ];
app.use(errorHandler);
if (config.basicAuthUser) {
  const basicAuth = auth({ name: config.basicAuthUser, pass: config.basicAuthPassword });
  app.use(basicAuth);
}
app.use(mount('/api', apiApp));
app.use(conditional());
app.use(etag());
app.use(compress());
app.use(mount('/', koaStatic(__dirname + '/../client')));
app.use(async (ctx) => {
  // return index.html for anything that is not handled
  ctx.body = await Promise.fromCallback(cb => fs.readFile(__dirname + '/../client/index.html', 'utf-8', cb));
});

export default app;
github open-wc / open-wc / packages / es-dev-server / src / server.js View on Github external
const app = new Koa();
  /** @type {import('chokidar').FSWatcher | null} */
  const fileWatcher = watch ? chokidar.watch([]) : null;

  // add custom user's middlewares
  if (customMiddlewares && customMiddlewares.length > 0) {
    customMiddlewares.forEach(customMiddleware => {
      app.use(customMiddleware);
    });
  }

  // serves 304 responses if resource hasn't changed
  app.use(createCacheMiddleware());
  // adds etag headers for caching
  app.use(koaEtag());

  // communicate with browser for reload or logging
  if (setupMessageChanel) {
    app.use(createMessageChannelMiddleware({ rootDir, appIndex }));
  }

  // watch files and reload browser
  if (watch) {
    app.use(
      createReloadBrowserMiddleware({
        rootDir,
        fileWatcher,
        watchExcludes,
        watchDebounce,
      }),
    );
github zalando / zappr / server / server.js View on Github external
exposableErrorTypes: [
                CHECK_ERROR_TYPE,
                GITHUB_ERROR_TYPE,
                REPO_ERROR_TYPE
              ]
            }))
            .use(morgan(morganFormat, {skip: morganSkip}))
            .use(convert(session({store: store})))
            .use(bodyParser())
            .use(passport.initialize())
            .use(passport.session())
            .use(compress())
            .use(router.routes())
            .use(router.allowedMethods())
            .use(conditional())
            .use(etag())
            .use(serve(
              nconf.get('STATIC_DIR'), {
                index: 'none',
                maxage: 1.7 * 10 ** 8 // ~ 2 days
              }))
            .use(ensureModeMiddleware)
            .use(renderStatic)
}
github mgenev / nautilus / server / config / koa.js View on Github external
module.exports = function (app) {
  // middleware configuration
  app.use(responseTime);
  app.use(cors());
  app.use(conditional());
  app.use(etag());
  app.use(bodyParser());
  app.use(authenticate);
  app.use(router(app));
  app.use(logger());

  // create all models first so controllers have them available
  let model, schema;
  for (let name of require('fs').readdirSync(__dirname+'/../models')) {
    if (name[0] === '.') return;
    name = name.substring(0, name.length - 3);
    schema = require('../models/' + name);
    model = mongoose.model(name, schema);
  };

  // auto mount all the simple routes defined in the api controllers
  // initialize complex custom defined routes
github patternplate / patternplate / packages / boilerplate-server / source / application / middlewares / etags.js View on Github external
export default function startEtagsMiddleware(application) {
  application.engine.use(conditional());

  application.engine.use(function* test(next) {
    yield next;
  });

  return etag();
}
github ditojs / dito / packages / server / src / app / Application.js View on Github external
}
    if (logger) {
      this.use(logger())
    }
    if (app.helmet !== false) {
      this.use(helmet())
    }
    if (app.cors !== false) {
      this.use(cors(isObject(app.cors) ? app.cors : {}))
    }
    if (app.compress !== false) {
      this.use(compress(app.compress))
    }
    if (app.etag !== false) {
      this.use(conditional())
      this.use(etag())
    }
  }

koa-etag

ETag support for koa

MIT
Latest version published 4 years ago

Package Health Score

62 / 100
Full package analysis

Popular koa-etag functions