Skip to content

fix: stop dropping cache:false on /api/security/** - #2144

Merged
emlimlf merged 2 commits into
mainfrom
fix/DE-1044
Sep 1, 2026
Merged

fix: stop dropping cache:false on /api/security/**#2144
emlimlf merged 2 commits into
mainfrom
fix/DE-1044

Conversation

@emlimlf

@emlimlf emlimlf commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes DE-1044 — clicking Update results on the Security & Best Practices page returns a 500 for every project.

  • /api/security/** (and /api/**) was declared in both top-level routeRules and nitro.routeRules in frontend/setup/caching.ts. Nitro doesn't merge two rules for the same exact pattern — the later one replaces the earlier wholesale — so cache: false was silently dropped and the route fell through to the /** catch-all's redis cache.
  • Nitro's cachedEventHandler wrapper then clones the incoming POST request without preserving content-length/content-type, so readBody() in update.post.ts returned undefined, and body.slug threw an unhandled TypeError → 500.
  • Root cause confirmed live against prod pod logs (stack trace through cachedEventHandler), not guessed.

Changes

  • frontend/setup/caching.ts: collapsed the duplicated route-rule keys into single declarations; deleted dead /api/**/*.post|.put|.delete|.patch rules that never matched (route rules match paths, not handler filenames).
  • frontend/server/api/security/update.post.ts: guard against an undefined body (body?.slug), compute workflowId before the try so it's available for error logging, and re-throw already-typed errors (404 project not found, 400 repo mismatch) instead of masking them as a generic 500.
  • frontend/setup/caching.test.ts: added a direct regression test asserting /api/security/** keeps cache: false in production, plus a static-analysis test guarding against any route pattern being declared twice.

Test plan

  • pnpm test setup/caching.test.ts — 6/6 passing, including the new DE-1044 regression test
  • pnpm tsc-check — clean
  • pnpm lint — 0 errors
  • NUXT_APP_ENV=production pnpm build — confirmed compiled nitro.mjs now has "cache": false alongside headers for /api/security/**
  • Post-deploy: click Update results on /project/electron-fdc3/repository/finos_fdc3-sail/security — expect success toast and a Temporal workflow started; a second immediate click should return a 429 "already in progress" toast, not a 500

🤖 Generated with Claude Code

/api/security/** was declared in both top-level routeRules and
nitro.routeRules; Nitro doesn't merge duplicate keys, so the nitro
entry silently replaced cache:false, letting the route fall through
to the redis catch-all. Nitro's cachedEventHandler then stripped the
POST body before update.post.ts ever read it, causing a 500 on every
"Update results" click.

Collapse the duplicate declarations into one, remove dead
*.post/.put/.delete/.patch rules that never matched, guard against
undefined body in the handler, and stop masking 404/400 errors as 500
in the catch block.

Signed-off-by: Efren Lim <elim@linuxfoundation.org>
Copilot AI balanced review requested due to automatic review settings September 1, 2026 10:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes production failures when triggering security updates by preserving no-cache rules and improving API error handling.

Changes:

  • Consolidates duplicate caching rules.
  • Adds route-rule regression tests.
  • Improves request-body and typed-error handling.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
frontend/setup/caching.ts Consolidates API caching configuration.
frontend/setup/caching.test.ts Tests cache rules and duplicate patterns.
frontend/server/api/security/update.post.ts Guards missing bodies and preserves typed errors.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

const { slug } = body;
// Sanitize repoUrl for use in workflowId (replace non-alphanumeric chars with dashes).
// Computed before the try so it's available to the catch block's error log.
const sanitizedRepo = body.repoUrl.replace(/[^a-zA-Z0-9]/g, '-').replace(/-+/g, '-');
Comment on lines +128 to +131
// Re-throw errors already thrown above (404 project not found, 400 repo mismatch) instead
// of masking them as a generic 500 below.
if (err && typeof err === 'object' && 'statusCode' in err) {
throw err;
Comment on lines +11 to 13
afterEach(() => {
process.env.NUXT_APP_ENV = originalAppEnv;
});
Copilot AI review requested due to automatic review settings September 1, 2026 10:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (1)

frontend/setup/caching.test.ts:12

  • When NUXT_APP_ENV was initially unset, assigning undefined to process.env stores the literal string "undefined" instead of removing the variable. This leaves the worker with a mutated environment after the suite and can affect later tests; delete the key when there was no original value.
    process.env.NUXT_APP_ENV = originalAppEnv;

@emlimlf
emlimlf merged commit aa7d99a into main Sep 1, 2026
12 checks passed
@emlimlf
emlimlf deleted the fix/DE-1044 branch September 1, 2026 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants