-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.mjs
36 lines (32 loc) · 918 Bytes
/
index.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import EventEmitter from 'events'
import koaCompress from 'koa-compress'
class Compress extends EventEmitter {
description () {
return 'Compress responses using gzip.'
}
optionDefinitions () {
return [
{
name: 'compress',
alias: 'z',
type: Boolean,
description: 'Serve gzip-compressed resources, where applicable.'
},
{
name: 'compress.threshold',
type: Number,
description: 'Minimum response size in bytes to apply compression. Defaults to 1024.'
}
]
}
middleware (options = {}) {
const mwOptions = {}
if (options.compress) mwOptions.compress = true
if (options.compressThreshold) mwOptions.threshold = options.compressThreshold
if (mwOptions.compress) {
this.emit('verbose', 'middleware.compress.config', mwOptions)
return koaCompress(mwOptions)
}
}
}
export default Compress