forked from magento/pwa-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for express server compression middleware. (magento#2980)
* Added compression middleware controlled by ENABLE_UPWARD_TEXT_COMPRESSION env variable. * ENABLE_UPWARD_TEXT_COMPRESSION -> ENABLE_EXPRESS_SERVER_COMPRESSION * Added express middleware to validate gzip compression. * Removing Gzip validation middleware. * Minor. * Moving the compression logic to buildpack. * Updated PWADevServer tests. * Added serve module tests. * Mocking env for snapshot tests. * Minor. * Checking for undefined PORT. * Minor * Enabling compression in prod mode. Co-authored-by: Devagouda <[email protected]>
- Loading branch information
1 parent
23c72da
commit 5e38b33
Showing
15 changed files
with
707 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
241 changes: 241 additions & 0 deletions
241
packages/pwa-buildpack/lib/Utilities/__tests__/__snapshots__/serve.spec.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should add compression middleware if ENABLE_EXPRESS_SERVER_COMPRESSION is true 1`] = ` | ||
Object { | ||
"error": Array [], | ||
"info": Array [ | ||
"PORT is set in environment: 1234", | ||
"NODE_ENV=production, will not attempt to use custom host or port", | ||
"Launching UPWARD server | ||
", | ||
], | ||
"success": Array [ | ||
" | ||
UPWARD server running.", | ||
], | ||
"warn": Array [], | ||
} | ||
`; | ||
|
||
exports[`should add the Image Opt middleware 1`] = ` | ||
Array [ | ||
Array [ | ||
Object {}, | ||
Object {}, | ||
], | ||
] | ||
`; | ||
|
||
exports[`should add the Image Opt middleware 2`] = ` | ||
Object { | ||
"error": Array [], | ||
"info": Array [ | ||
"PORT is set in environment: 1234", | ||
"NODE_ENV=production, will not attempt to use custom host or port", | ||
"Launching UPWARD server | ||
", | ||
], | ||
"success": Array [ | ||
" | ||
UPWARD server running.", | ||
], | ||
"warn": Array [], | ||
} | ||
`; | ||
|
||
exports[`should create upward server 1`] = ` | ||
Array [ | ||
Array [ | ||
Object { | ||
"before": [Function], | ||
"bindLocal": true, | ||
"env": Object { | ||
"ENABLE_EXPRESS_SERVER_COMPRESSION": "false", | ||
"PORT": "1234", | ||
}, | ||
"logUrl": true, | ||
"port": "1234", | ||
}, | ||
], | ||
] | ||
`; | ||
|
||
exports[`should create upward server 2`] = `"Server Object"`; | ||
|
||
exports[`should create upward server 3`] = ` | ||
Object { | ||
"error": Array [], | ||
"info": Array [ | ||
"PORT is set in environment: 1234", | ||
"NODE_ENV=production, will not attempt to use custom host or port", | ||
"Launching UPWARD server | ||
", | ||
], | ||
"success": Array [ | ||
" | ||
UPWARD server running.", | ||
], | ||
"warn": Array [], | ||
} | ||
`; | ||
|
||
exports[`should log error if configureHost throws error 1`] = ` | ||
Object { | ||
"error": Array [ | ||
"Could not configure or access custom host. Using loopback...", | ||
"unable to configure host", | ||
], | ||
"info": Array [ | ||
"PORT is set in environment: 7899", | ||
"Launching UPWARD server | ||
", | ||
], | ||
"success": Array [ | ||
" | ||
UPWARD server running.", | ||
], | ||
"warn": Array [], | ||
} | ||
`; | ||
|
||
exports[`should not add compression middleware if ENABLE_EXPRESS_SERVER_COMPRESSION is false 1`] = ` | ||
Object { | ||
"error": Array [], | ||
"info": Array [ | ||
"PORT is set in environment: 1234", | ||
"NODE_ENV=production, will not attempt to use custom host or port", | ||
"Launching UPWARD server | ||
", | ||
], | ||
"success": Array [ | ||
" | ||
UPWARD server running.", | ||
], | ||
"warn": Array [], | ||
} | ||
`; | ||
|
||
exports[`should throw error if unable to load env 1`] = `[Error: Can not load environment config!]`; | ||
|
||
exports[`should throw error if unable to load env 2`] = ` | ||
Object { | ||
"error": Array [], | ||
"info": Array [], | ||
"success": Array [], | ||
"warn": Array [], | ||
} | ||
`; | ||
|
||
exports[`should use configureHost config if custom origin is enabled 1`] = ` | ||
Array [ | ||
Array [ | ||
Object { | ||
"dir": "pwa-buildpack", | ||
"enabled": true, | ||
"interactive": false, | ||
}, | ||
], | ||
] | ||
`; | ||
|
||
exports[`should use configureHost config if custom origin is enabled 2`] = ` | ||
Object { | ||
"error": Array [], | ||
"info": Array [ | ||
"PORT is set in environment: 7899", | ||
"Launching UPWARD server | ||
", | ||
], | ||
"success": Array [ | ||
" | ||
UPWARD server running.", | ||
], | ||
"warn": Array [], | ||
} | ||
`; | ||
|
||
exports[`should use env.PORT if provided 1`] = ` | ||
Object { | ||
"error": Array [], | ||
"info": Array [ | ||
"PORT is set in environment: 7899", | ||
"NODE_ENV=production, will not attempt to use custom host or port", | ||
"Launching UPWARD server | ||
", | ||
], | ||
"success": Array [ | ||
" | ||
UPWARD server running.", | ||
], | ||
"warn": Array [], | ||
} | ||
`; | ||
|
||
exports[`should use port 0 if both env.PORT and staging config port are falsy 1`] = ` | ||
Object { | ||
"error": Array [], | ||
"info": Array [ | ||
"NODE_ENV=production, will not attempt to use custom host or port", | ||
"Launching UPWARD server | ||
", | ||
], | ||
"success": Array [ | ||
" | ||
UPWARD server running.", | ||
], | ||
"warn": Array [ | ||
"No port set. Binding to OS-assigned port", | ||
], | ||
} | ||
`; | ||
|
||
exports[`should use staging server port if env.PORT is not defined 1`] = ` | ||
Object { | ||
"error": Array [], | ||
"info": Array [ | ||
"STAGING_SERVER_PORT is configured: 5678", | ||
"NODE_ENV=production, will not attempt to use custom host or port", | ||
"Launching UPWARD server | ||
", | ||
], | ||
"success": Array [ | ||
" | ||
UPWARD server running.", | ||
], | ||
"warn": Array [], | ||
} | ||
`; | ||
|
||
exports[`should use staging server port if env.PORT is null 1`] = ` | ||
Object { | ||
"error": Array [], | ||
"info": Array [ | ||
"STAGING_SERVER_PORT is configured: 5678", | ||
"NODE_ENV=production, will not attempt to use custom host or port", | ||
"Launching UPWARD server | ||
", | ||
], | ||
"success": Array [ | ||
" | ||
UPWARD server running.", | ||
], | ||
"warn": Array [], | ||
} | ||
`; | ||
|
||
exports[`should use staging server port if env.PORT is undefined 1`] = ` | ||
Object { | ||
"error": Array [], | ||
"info": Array [ | ||
"STAGING_SERVER_PORT is configured: 5678", | ||
"NODE_ENV=production, will not attempt to use custom host or port", | ||
"Launching UPWARD server | ||
", | ||
], | ||
"success": Array [ | ||
" | ||
UPWARD server running.", | ||
], | ||
"warn": Array [], | ||
} | ||
`; |
Oops, something went wrong.