Skip to content

Move from Spotify to TIDAL, rebuilt for speed, and ready for Vercel - #3

Merged
renderghost merged 6 commits into
mainfrom
claude/dazzling-cray-udk74u
Oct 25, 2026
Merged

renderghost merged 6 commits into
mainfrom
claude/dazzling-cray-udk74u

Conversation

@renderghost

Copy link
Copy Markdown
Owner

Summary

Replaces Spotify with TIDAL and rebuilds the site to be faster, responsive on every screen size, and resilient. It is ready to deploy on Vercel.

  • TIDAL: all public playlists and their cover art come from TIDAL's v2 API in paginated requests, instead of one request per playlist. TIDAL only lists a user's playlists to an app signed in as that user, so there is a one-time sign-in helper: npm run tidal:login -- --save. Private and unlisted playlists are never shown.
  • Browsing: an artwork-first grid, live search over titles, artist/genre tags (taken from the "(…)" in titles) and descriptions, tag filters, sorting, and a shareable URL for every view.
  • Playlist popover: a native modal dialog with TIDAL's embedded player, plus Open in TIDAL and Copy link. Esc, the Back button and clicking outside all close it.
  • Speed:
    • Return visits render instantly from the browser's saved copy, then usually get an empty 304 back. When something has changed, only new or edited playlists are downloaded.
    • Artwork is lazy-loaded and sized to fit each card.
    • CSS, JS and fonts use content-hashed URLs and are cached for a year. The font is self-hosted.
    • On Vercel, the CDN also caches the playlist data.
  • Errors:
    • Visitors see clear messages with retry, offline and empty states.
    • Server logs are structured JSON with a request ID on every line.
    • Browser errors and Content-Security-Policy violations are reported back to the server.
    • Sentry is optional (set SENTRY_DSN).
    • /healthz reports health, and the server keeps serving the last good copy if TIDAL is down.
  • Vercel: app.js exports the Express app as a Vercel Function. vercel.json handles static asset rewrites, caching and function settings. Background work runs through waitUntil.

Deploying

  1. Import the repository in Vercel. Vercel detects the Express app, and no build settings are needed.
  2. Add these environment variables: TIDAL_CLIENT_ID, TIDAL_CLIENT_SECRET, TIDAL_USER_ID, TIDAL_REFRESH_TOKEN, and optionally TIDAL_PROFILE_URL, SENTRY_DSN, and SITE_URL (only for a custom domain).
  3. Check /healthz on the preview deployment.

Testing

  • npm test: 103 tests covering the TIDAL client, catalogue, HTTP API, configuration, error reporting and the browser's sync/search logic. npm run check syntax-checks all JS. Both run in CI on Node 22 and 24.
  • Tested in a real browser at desktop, tablet and phone sizes, using demo data (npm run dev:mock).
  • Tested against the real TIDAL account: 202 public playlists loaded.
  • Simulated the Vercel runtime locally: the exported app served the real catalogue, the CDN cache header, versioned assets and the health check.
  • Not yet verified on Vercel itself: this PR's preview deployment is the first real run there.

🤖 Generated with Claude Code

claude and others added 6 commits October 25, 2026 14:03
Replace the Spotify integration with TIDAL's v2 API and rebuild the site
for speed, responsiveness and resilience.

Server
- Fetch all public playlists and their cover art in a few paginated
  requests (filter[owners.id] + include=coverArt) instead of one request
  per playlist.
- Client-credentials auth by default, with a refresh-token fallback and a
  one-time PKCE sign-in helper (npm run tidal:login) in case TIDAL requires
  a user to read playlists.
- Retries with backoff for network errors, 429 (Retry-After) and 5xx;
  a fresh token on 401; typed errors that carry TIDAL's own details.
- Only public playlists are ever exposed, whichever credentials are used.
- Catalogue served from memory with stale-while-revalidate, a
  last-known-good snapshot on disk, and back-off while TIDAL is failing.
- Manifest + delta API with ETags, so browsers fetch only what changed.
- Security headers with a per-request CSP nonce; CSP violation and browser
  error intake; structured logs with request ids; optional Sentry;
  health endpoint; graceful shutdown.
- Content-hashed asset URLs served immutable, without a build step.

Browser
- Renders instantly from a localStorage copy, then syncs: usually a
  bodiless 304, otherwise only new or changed playlists are downloaded.
- Artwork-first responsive grid: srcset/sizes, lazy loading, first-row
  priority hints and palette-colour placeholders.
- Live search over titles, tags and descriptions; artist/genre tags parsed
  from titles; sorting; shareable URLs for every view.
- Native modal dialog with TIDAL's embedded player, Open in TIDAL and
  Copy link; Back button and Esc close it; light dismiss.
- Clear error, offline, empty and retry states; errors reported to the
  server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YXBoVxYxPpig7Tkb6fDbc6
- 97 tests on Node's built-in runner: title/tag parsing, artwork
  selection, privacy filtering, token handling, retries, pagination,
  catalogue refresh/back-off/snapshots, the HTTP API (ETags, 304s, errors,
  security headers, caching), report intake, configuration, and the
  browser's search, formatting and delta-sync logic.
- GitHub Actions runs a syntax check and the tests on Node 22 and 24 for
  every pull request and push to main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YXBoVxYxPpig7Tkb6fDbc6
Setup, the TIDAL sign-in fallback, deployment on Render, how caching and
syncing work, error handling and reporting, and the project layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YXBoVxYxPpig7Tkb6fDbc6
With client credentials, TIDAL answers a filter[owners.id] query with an
empty list rather than an error, so the site showed "0 playlists" with
the loading skeletons stuck on screen.

- Treat an empty result under client credentials as a sign-in problem
  and say how to fix it (npm run tidal:login -- --save).
- Ignore empty snapshots on disk so one can't outlive the fix.
- Always replace the loading skeletons on the first render, including
  empty results and failed loads, and show a message when there are no
  playlists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Pause 400ms between pages of TIDAL results. Back-to-back pages were
  hitting TIDAL's rate limit (429), which the retries absorbed but which
  slowed a cold start to ~14s.
- Log retries as one line instead of a full stack trace.
- Don't log /.well-known/ probes (Chrome DevTools asks for one on every load).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Vercel runs Express apps as a function rather than a long-running server.

- app.js exports the Express app; it only listens on a port off Vercel.
  Start-up is split into createSite() and serve() in src/site.js.
- vercel.json maps versioned /static/<hash>/ URLs onto public/ (served by
  Vercel's CDN, cached for a year), bundles views/ and public/ into the
  function, and allows 60s for a cold fetch from TIDAL.
- Playlist API responses carry Vercel-CDN-Cache-Control (10 min, with
  stale-while-revalidate), so visitors rarely wait for TIDAL. Browsers
  still revalidate with ETags. Errors and the page are never CDN-cached.
- Background refreshes and Sentry flushes go through waitUntil, so they
  finish after the response is sent.
- The playlist snapshot is written to the temp directory on Vercel.
- SITE_URL, release and environment default from Vercel's system variables.
- README deployment guide rewritten for Vercel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@renderghost
renderghost merged commit ef5ca1a into main Oct 25, 2026
2 checks passed
@renderghost
renderghost deleted the claude/dazzling-cray-udk74u branch October 25, 2026 16:23
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.

2 participants