文件服务后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 1 година
123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * Http compression router
  3. * @author tala
  4. * 2018-05-23
  5. */
  6. 'use strict'
  7. const compression = require('compression')
  8. class HttpCompression {
  9. constructor(policyRouter) {
  10. this._policyRouter = policyRouter
  11. }
  12. init() {
  13. let self = this
  14. // compression
  15. self._policyRouter.use('/', compression({
  16. filter: function(req, res) {
  17. if (req.headers['x-no-compression']) {
  18. // don't compress responses with this request header
  19. return false;
  20. }
  21. // fallback to standard filter function
  22. return compression.filter(req, res);
  23. }
  24. }), {
  25. name: 'httpCompression',
  26. })
  27. return self
  28. }
  29. }
  30. module.exports = HttpCompression