feat: add compression middleware with brotli support (closes #218)#300
Open
aojomo wants to merge 1 commit into
Open
feat: add compression middleware with brotli support (closes #218)#300aojomo wants to merge 1 commit into
aojomo wants to merge 1 commit into
Conversation
- Install compression package v1.8.1 with native brotli support via Node zlib - Create src/middleware/compression.ts with 1 KB threshold and /metrics exclusion - Wire compression middleware into Express stack before route handlers - Add Content-Encoding and Vary header verification to smoke-health.sh - Brotli (br) preferred when client advertises Accept-Encoding: br Closes Neurowealth#218
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds response compression middleware to reduce bandwidth usage and improve mobile latency for API responses — especially analytics, transaction history, and agent logs.
Closes #218
Changes
New file:
src/middleware/compression.tsConfigured compression middleware with:
zlib.createBrotliCompresswhen the client advertisesAccept-Encoding: br, falling back to gzip, then deflateModified:
src/index.tsapp.use()before route handlers but after security/parsing/rate-limit middleware — the correct position in the middleware stackModified:
scripts/smoke-health.shVary: Accept-Encodingheader (always set by middleware regardless of body size) — confirms middleware is activeContent-Encodingheader on larger endpoints — confirms actual compression when body exceeds 1 KB thresholdDependencies
compressionv1.8.1 (the standard Express compression middleware package with native brotli support via Node.jszlib)@types/compressionv1.8.1Acceptance Criteria
Accept-Encoding: br)/metricsexcluded from compressionContent-Encodingon compressible responsesTesting