Skip to content
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’ll 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

manniL
Copy link
Member

@manniL 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: docs(renderer): Add compressor behavior 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 September 8, 2018 13:48
@codecov-io
Copy link

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.

Copy link
Member

@clarkdo clarkdo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@manniL
Copy link
Member Author

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
Copy link
Member

clarkdo commented Sep 8, 2018

Yeah, how do you think?
compressor or compression ?

@manniL
Copy link
Member Author

manniL commented Sep 8, 2018

Sounds great and will make things definitely easier! I'm on it! ☺️

@manniL
Copy link
Member Author

manniL commented Sep 8, 2018

After thinking a few minutes, compressor might fit better ☺️

@manniL manniL force-pushed the feat-customizable-compression-middleware branch from 3390308 to 09b5383 Compare September 8, 2018 14:59
@manniL manniL force-pushed the feat-customizable-compression-middleware branch from 09b5383 to 3a15940 Compare September 8, 2018 15:10
@manniL manniL force-pushed the feat-customizable-compression-middleware branch from 3a15940 to d391655 Compare September 8, 2018 15:12
@manniL manniL requested a review from clarkdo September 8, 2018 15:24
@manniL
Copy link
Member Author

manniL commented Sep 8, 2018

If everything fits I'd write the docs and then this PR is good to go ☺️

lib/common/nuxt.config.js Outdated Show resolved Hide resolved
lib/core/renderer.js Outdated Show resolved Hide resolved
@manniL manniL requested a review from clarkdo September 8, 2018 16:12
@@ -4,6 +4,7 @@ import fs from 'fs'
import _ from 'lodash'
import consola from 'consola'

import compressionMiddleware from 'compression'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m 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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've renamed it 👌

Could you explain how you mean lazy loading it?

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

lib/common/options.js Outdated Show resolved Hide resolved
@pi0
Copy link
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 feat-customizable-compression-middleware branch from fe50958 to 134a26f Compare September 8, 2018 19:02
@manniL manniL force-pushed the feat-customizable-compression-middleware branch from 2046e78 to 4d69f11 Compare September 8, 2018 19:13
@pi0 pi0 merged commit b74d537 into nuxt:dev Sep 8, 2018
@manniL manniL deleted the feat-customizable-compression-middleware branch September 8, 2018 21:10
@manniL manniL mentioned this pull request Sep 13, 2018
2 tasks
clarkdo pushed a commit that referenced this pull request Sep 13, 2018
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
Copy link

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
@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants