Skip to content

Commit

Permalink
fix(core): use gzip compression for responses (#4385)
Browse files Browse the repository at this point in the history
  • Loading branch information
allardy committed Jan 20, 2021
1 parent 78e215c commit a4677ec
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -34,6 +34,7 @@
"cerialize": "^0.1.18",
"chalk": "^2.4.2",
"chokidar": "^2.1.5",
"compression": "^1.7.4",
"cookie-session": "^1.3.3",
"cors": "^2.8.5",
"debug": "^4.1.1",
Expand Down
5 changes: 5 additions & 0 deletions src/bp/core/server.ts
Expand Up @@ -2,6 +2,7 @@ import bodyParser from 'body-parser'
import { AxiosBotConfig, AxiosOptions, http, Logger, RouterOptions } from 'botpress/sdk'
import LicensingService from 'common/licensing-service'
import { RequestWithUser } from 'common/typings'
import compression from 'compression'
import session from 'cookie-session'
import cors from 'cors'
import errorHandler from 'errorhandler'
Expand Down Expand Up @@ -151,6 +152,10 @@ export default class HTTPServer {

this.app.use(debugRequestMw)

if (!yn(process.core_env.BP_HTTP_DISABLE_GZIP)) {
this.app.use(compression())
}

this.modulesRouter = new ModulesRouter(
this.logger,
this.authService,
Expand Down
5 changes: 5 additions & 0 deletions src/typings/global.d.ts
Expand Up @@ -128,6 +128,11 @@ declare interface BotpressEnvironmentVariables {
*/
readonly BP_PROXY?: string

/**
* Disable the use of GZIP compression while serving assets to the end users
*/
readonly BP_HTTP_DISABLE_GZIP?: boolean

/**
* Use to set default debug namespaces
* @example bp:dialog:*,bp:nlu:intents:*
Expand Down
25 changes: 25 additions & 0 deletions yarn.lock
Expand Up @@ -2320,6 +2320,26 @@ component-inherit@0.0.3:
resolved "https://registry.yarnpkg.com/component-inherit/-/component-inherit-0.0.3.tgz#645fc4adf58b72b649d5cae65135619db26ff143"
integrity sha1-ZF/ErfWLcrZJ1crmUTVhnbJv8UM=

compressible@~2.0.16:
version "2.0.18"
resolved "https://registry.yarnpkg.com/compressible/-/compressible-2.0.18.tgz#af53cca6b070d4c3c0750fbd77286a6d7cc46fba"
integrity sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==
dependencies:
mime-db ">= 1.43.0 < 2"

compression@^1.7.4:
version "1.7.4"
resolved "https://registry.yarnpkg.com/compression/-/compression-1.7.4.tgz#95523eff170ca57c29a0ca41e6fe131f41e5bb8f"
integrity sha512-jaSIDzP9pZVS4ZfQ+TzvtiWhdpFhE2RDHz8QJkpX9SIpLq88VueF5jJw6t+6CUQcAoA6t+x89MLrWAqpfDE8iQ==
dependencies:
accepts "~1.3.5"
bytes "3.0.0"
compressible "~2.0.16"
debug "2.6.9"
on-headers "~1.0.2"
safe-buffer "5.1.2"
vary "~1.1.2"

concat-map@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
Expand Down Expand Up @@ -6584,6 +6604,11 @@ mime-db@1.44.0:
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.44.0.tgz#fa11c5eb0aca1334b4233cb4d52f10c5a6272f92"
integrity sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==

"mime-db@>= 1.43.0 < 2":
version "1.45.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.45.0.tgz#cceeda21ccd7c3a745eba2decd55d4b73e7879ea"
integrity sha512-CkqLUxUk15hofLoLyljJSrukZi8mAtgd+yE5uO4tqRZsdsAJKv0O+rFMhVDRJgozy+yG6md5KwuXhD4ocIoP+w==

mime-db@~1.38.0:
version "1.38.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.38.0.tgz#1a2aab16da9eb167b49c6e4df2d9c68d63d8e2ad"
Expand Down

0 comments on commit a4677ec

Please sign in to comment.