Skip to content

fix(visitors): hide footer stats when Upstash isn't configured - #425

Merged
anurag629 merged 1 commit into
codercops:devfrom
Seyamalam:fix/hide-visitor-counter-without-upstash
Nov 18, 2026
Merged

anurag629 merged 1 commit into
codercops:devfrom
Seyamalam:fix/hide-visitor-counter-without-upstash

Conversation

@Seyamalam

Copy link
Copy Markdown
Contributor

Description

OGCOPS "requires no environment variables for basic usage", but without UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN the footer still rendered a Stats block stuck on placeholder dashes, and every page load logged a failed /api/visitors 500 in the console — for every contributor running npm run dev and for visitors of any self-hosted copy without the counter.

/api/visitors now answers 204 No Content to GET and POST when either secret is missing, without calling Upstash; a real Upstash failure with the secrets set still returns 500. The footer script checks r.status before r.json() — on any non-200 it hides the Stats title and counter row while keeping the MIT License / copyright line, and remembers that result so footers swapped in on client-side navigations are hidden the same way.

Closes #420

How I Tested This

  • npx vitest run tests/api/visitors.test.ts — 10 new tests: GET and POST return 204 with no fetch call when neither or only one secret is set; with both set, GET/POST return the counts, and a real Upstash failure still returns 500. astro:env/server is mocked the way tests/middleware.test.ts mocks astro:middleware, and fetch is stubbed.
  • Confirmed the tests fail without the fix: removed the guard in src/pages/api/visitors.ts, reran the file — the 204 cases returned the old 500; then restored the fix.
  • npm run dev with no .env: curl -i http://localhost:4321/api/visitors → 204 No Content; curl -i -X POST -H 'Content-Type: application/json' -H 'Origin: http://localhost:4321' http://localhost:4321/api/visitors → 204 No Content; footer shows no Stats block and no console 500 (screenshot below).
  • npm run check, npm run test (2120 tests), and npm run build all pass.

AI Assistance

Devin CLI (SWE-2 High): implemented the route guard, the footer script change, and the new test file under human direction; the diff was reviewed and verified by the operator before filing.

Type of Change

  • Bug fix

Screenshots

Footer before/after

Checklist

  • This PR targets dev
  • I was assigned the linked issue
  • npm run check passes
  • npm run test passes
  • For a bug fix: the new test fails without my change
  • Tested locally with npm run dev
  • Screenshots included for visual changes
  • New templates follow the Template Guidelines (N/A — no template changes)

Created with SWE-2 High in Devin CLI.

Without UPSTASH_REDIS_REST_URL/TOKEN the API 500'd and the footer showed
a broken Stats block on every page. The route now answers 204 for GET and
POST when either secret is missing, and the footer hides the Stats block
on any non-200 response, remembering it across client-side navigations.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@anurag629 anurag629 closed this Nov 17, 2026
@anurag629 anurag629 reopened this Nov 17, 2026
@anurag629 anurag629 added the codercops-accepted Merged PR that counts on the monthly leaderboard (oss.codercops.com) label Nov 18, 2026
@anurag629
anurag629 merged commit 75f0727 into codercops:dev Nov 18, 2026
4 checks passed
@anurag629

Copy link
Copy Markdown
Member

Hey @Seyamalam, thanks again for this one! If you haven't yet, come join our Discord (https://discord.gg/mpGdJyjaRQ) and run /link there to connect your GitHub, so you get the Contributor role and your merges show up with your name in the shoutouts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codercops-accepted Merged PR that counts on the monthly leaderboard (oss.codercops.com)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Footer: hide the visitor counter when Upstash isn't set up

2 participants