feat(backend): response caching with ETag support and per-route TTLs#174
Merged
Smartdevs17 merged 2 commits intoSmartdevs17:mainfrom Mar 29, 2026
Merged
Conversation
…ollback (Smartdevs17#46) Adds scripts/deploy.sh implementing the full deployment lifecycle: - Build: runs `npm ci && npm run build` for backend (TypeScript/tsc) and frontend (Next.js) independently; each can be skipped via flags - Database migration hook: structured no-op with commented-out stubs for Prisma, TypeORM, and custom migration scripts — ready to activate when a database is introduced - Zero-downtime reload: uses PM2 `reload` for in-place restarts of existing processes; `start` for first-time deploys - Health check: polls GET /health (up to 12 × 5s) and accepts both `healthy` and `degraded` status responses (HTTP 200/206) - Automatic rollback: backs up dist/ and .next/ before each deploy; restores and reloads processes if the health check fails - Manual rollback: `./scripts/deploy.sh --rollback` restores the last saved backup at any time Flags: --env <staging|production>, --skip-frontend, --skip-backend, --skip-migrations, --rollback Closes Smartdevs17#46
…TLs (Smartdevs17#17) Adds backend/src/middleware/cache.ts — a cacheControl() middleware factory that handles all three acceptance criteria: Cache-Control headers Sets `public/private, max-age=N [, stale-while-revalidate=M]` on GET/HEAD responses. Mutation methods (POST/PUT/PATCH/DELETE) receive `no-store` via a global middleware in index.ts so they are never accidentally cached. ETag support Intercepts res.json(), serialises the body, and computes a 16-char SHA-1 ETag. On subsequent requests that include `If-None-Match`, the middleware short-circuits and returns 304 Not Modified without re-sending the payload. Configurable per-route durations CacheTTL constants define four tiers: STATIC (300 s) — catalog (rarely changes) SHORT (30 s) — stellar account balances, verification results IMMUTABLE (600 s)— confirmed Stellar transactions (never change) NONE (0) — explicit no-store Routes updated: GET /api/v1/catalog → STATIC (300 s + stale-while-revalidate=60) GET /api/v1/stellar/account/:a → SHORT (30 s) GET /api/v1/stellar/tx/:hash → IMMUTABLE (600 s) GET /api/v1/verification/:id → SHORT (30 s) Tests: 16 unit tests covering Cache-Control header generation, ETag consistency, 304 conditional GET, non-GET passthrough, and no-store. Closes Smartdevs17#17
|
@gidson5 is attempting to deploy a commit to the smartdevs17's projects Team on Vercel. A member of the Team first needs to authorize it. |
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
backend/src/middleware/cache.ts— acacheControl()middleware factory covering all three acceptance criteria.What changed
backend/src/middleware/cache.tscacheControl()factory +CacheTTLconstantsbackend/src/middleware/__tests__/cache.test.tsbackend/src/index.tsno-storefor mutations +Vary: Accept-Encodingbackend/src/routes/catalog.tsSTATICcache (300 s +stale-while-revalidate=60)backend/src/routes/stellar.tsSHORTfor accounts (30 s),IMMUTABLEfor txs (600 s)backend/src/routes/verification.tsSHORTcache onGET /:id(30 s)Acceptance criteria
cacheControl()computes a SHA-1 ETag from the response body and returns304 Not ModifiedwhenIf-None-MatchmatchesCacheTTLconstants (STATIC/SHORT/IMMUTABLE/NONE) applied individually to each GET routepublic, max-age=Non cached GET responses;no-storeon all mutation methods via global middleware inindex.tsTest plan
npm test(vitest)curl -I /api/v1/catalogreturnsCache-Control: public, max-age=300and anETagIf-None-Match: <etag>receives304 Not ModifiedCache-Control: no-storeCloses #17
🤖 Generated with Claude Code