New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make compression middleware customizable #3863

Merged
merged 14 commits into from Sep 8, 2018

Conversation

Projects
None yet
4 participants
@manniL
Member

manniL commented Sep 8, 2018

Let user customize compression middleware

Types of changes

  • New feature (non-breaking change which adds functionality)

Description

The user can now set up his own compression middleware on render.customCompressionMiddleware which will then be used instead of compression.

Could help with Likely resolves #3117 馃憤 (have to test it on HTTPS first)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly. (PR: nuxt/docs#749)
  • I have added tests to cover my changes (if not applicable, please state why)
  • All new and existing tests passed.

@manniL manniL requested review from pi0 and clarkdo Sep 8, 2018

@codecov-io

This comment has been minimized.

codecov-io commented Sep 8, 2018

Codecov Report

Merging #3863 into dev will decrease coverage by 0.31%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff            @@
##             dev    #3863      +/-   ##
=========================================
- Coverage   97.8%   97.48%   -0.32%     
=========================================
  Files         18       18              
  Lines       1183     1193      +10     
  Branches     325      328       +3     
=========================================
+ Hits        1157     1163       +6     
- Misses        25       28       +3     
- Partials       1        2       +1
Impacted Files Coverage 螖
lib/common/nuxt.config.js 100% <酶> (酶) 猬嗭笍
lib/core/renderer.js 100% <100%> (酶) 猬嗭笍
lib/common/options.js 95.23% <60%> (-4.77%) 猬囷笍

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update baaf67d...afd6cc3. Read the comment docs.

@clarkdo

How about using hook like render:before or move render.gzip to a common render.commpressor for denfining custom compression lib.

@manniL

This comment has been minimized.

Member

manniL commented Sep 8, 2018

@clarkdo You mean like:

render.compression is an object -> use compression with object as options
render.compression is a string or a function -> use useMiddleware to register it
render.compression is empty -> use compression with default options (or legacy render.gzip)

@clarkdo

This comment has been minimized.

Member

clarkdo commented Sep 8, 2018

Yeah, how do you think?
compressor or compression ?

@manniL

This comment has been minimized.

Member

manniL commented Sep 8, 2018

Sounds great and will make things definitely easier! I'm on it! 鈽猴笍

@manniL

This comment has been minimized.

Member

manniL commented Sep 8, 2018

After thinking a few minutes, compressor might fit better 鈽猴笍

@manniL manniL force-pushed the manniL:feat-customizable-compression-middleware branch from 3390308 to 09b5383 Sep 8, 2018

@manniL manniL force-pushed the manniL:feat-customizable-compression-middleware branch from 09b5383 to 3a15940 Sep 8, 2018

@manniL manniL force-pushed the manniL:feat-customizable-compression-middleware branch from 3a15940 to d391655 Sep 8, 2018

@manniL manniL requested a review from clarkdo Sep 8, 2018

@manniL

This comment has been minimized.

Member

manniL commented Sep 8, 2018

If everything fits I'd write the docs and then this PR is good to go 鈽猴笍

Show resolved Hide resolved lib/common/nuxt.config.js Outdated
Show resolved Hide resolved lib/core/renderer.js Outdated

@manniL manniL requested a review from clarkdo Sep 8, 2018

@@ -4,6 +4,7 @@ import fs from 'fs'
import _ from 'lodash'
import consola from 'consola'
import compressionMiddleware from 'compression'

This comment has been minimized.

@clarkdo

clarkdo Sep 8, 2018

Member

I鈥檓 not sure if put compression here is proper, maybe we can make it lazy required and make options.js only change config, @pi0 do you have any idea.
BTW name can be compression锛

This comment has been minimized.

@manniL

manniL Sep 8, 2018

Member

I've renamed it 馃憣

Could you explain how you mean lazy loading it?

In the end, it's "just" the server bundle anyway.

This comment has been minimized.

@clarkdo

clarkdo Sep 8, 2018

Member

require or nuxt.requireModule inside renderer so that we can support sth like: compressor: 鈥榗ustom-lib鈥 or compressor: { name: 鈥榗ompression鈥, options: {}}. Maybe I thought too much, current pr is good for me. Let鈥檚 ask @pi0 review and merge.

@clarkdo

clarkdo approved these changes Sep 8, 2018

Show resolved Hide resolved lib/common/options.js Outdated
@pi0

This comment has been minimized.

Member

pi0 commented Sep 8, 2018

Thanks, @manniL @clarkdo. Changes are quite good. But I think we should move compression initialization (retrieve) logic into renderer.js and also lazy require default compression middleware. This fact is true that compression is a dependency but when the user is using a custom one, it is not required.
About moving to init logic from options into renderer, we can check for deprecated render.gzip option and normalize it into render.compression but do the real require inside renderer because it's renderer job not options :)

@manniL manniL force-pushed the manniL:feat-customizable-compression-middleware branch from fe50958 to 134a26f Sep 8, 2018

@manniL manniL force-pushed the manniL:feat-customizable-compression-middleware branch from 2046e78 to 4d69f11 Sep 8, 2018

manniL and others added some commits Sep 8, 2018

@pi0

pi0 approved these changes Sep 8, 2018

@pi0 pi0 merged commit b74d537 into nuxt:dev Sep 8, 2018

7 checks passed

ci/circleci: build Your tests passed on CircleCI!
Details
ci/circleci: lint Your tests passed on CircleCI!
Details
ci/circleci: setup Your tests passed on CircleCI!
Details
ci/circleci: test-e2e Your tests passed on CircleCI!
Details
ci/circleci: test-unit Your tests passed on CircleCI!
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
security/snyk - package.json (Atinux) No manifest changes detected

@manniL manniL deleted the manniL:feat-customizable-compression-middleware branch Sep 8, 2018

@manniL manniL referenced this pull request Sep 13, 2018

Merged

Fix legacy gzip warning #3884

2 of 2 tasks complete

clarkdo added a commit that referenced this pull request Sep 13, 2018

Fix legacy gzip warning (#3884)
Fix legacy gzip warning. Thanks to @liam-potter for pointing that out!

Related PR: #3863 

## Types of changes

- [x] Bug fix (non-breaking change which fixes an issue)

## Checklist:
- [x] All new and existing tests passed.
@lock

This comment has been minimized.

lock bot commented Oct 31, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 31, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.