Skip to content

Conversation

@paprikaf
Copy link
Collaborator

@paprikaf paprikaf commented Dec 10, 2025

Screenshot 2025-12-16 at 11 22 22 AM

@github-actions
Copy link

github-actions bot commented Dec 10, 2025

🚀 Preview Deployment

Environment URL
Preview https://131-pr.crate.audio
Fallback https://crate-app-pr-131.govi218mu.workers.dev

Commit: cce2b19
Updated: 2025-12-17T20:21:41.649Z

This preview will be automatically deleted when the PR is closed.

@paprikaf paprikaf requested a review from govi218 December 10, 2025 13:33
@paprikaf paprikaf marked this pull request as draft December 13, 2025 00:56
@paprikaf paprikaf marked this pull request as ready for review December 13, 2025 05:02
- Update server-side Discogs routes to use process.env instead of import.meta.env
- Add fallback to VITE_DISCOGS_* for local development compatibility
- Use explicit wrangler secret put commands in all deployment workflows
- This fixes 401/500 errors on preview, staging, and production deployments
The correct way to access Cloudflare Worker secrets/bindings is via
the `env` object from `cloudflare:workers` module, not `process.env`.
Adds TypeScript type declarations for the cloudflare:workers module
which provides access to Worker bindings (secrets, vars, etc.)
- Add preview URL pattern (XXX-pr.crate.audio) to ALLOWED_ORIGINS
- Revert from cloudflare:workers env to process.env (works with nodejs_compat)
- Remove cloudflare:workers import from all Discogs API files

The 500 error was caused by preview URLs not being in the allowed origins list.
The separate "Set Worker Secrets" steps were not working - secrets were
not being set on the Workers. Using the built-in secrets parameter in
wrangler-action which handles this properly.

Maps GitHub secrets VITE_DISCOGS_CONSUMER_KEY and VITE_DISCOGS_CONSUMER_SECRET
to DISCOGS_CONSUMER_KEY and DISCOGS_CONSUMER_SECRET for the Worker.
The wrangler-action secrets parameter doesn't pass the --name flag,
so secrets were being set on the default worker instead of the
PR-specific worker. Using postCommands to explicitly run wrangler
secret put with the correct --name flag.
All API routes and the discogs lib now use the official Cloudflare way
to access secrets: import { env } from 'cloudflare:workers'
- cloudflare:workers bindings are empty in local dev
- Added fallback to process.env for Discogs credentials
- Created .dev.vars for local secrets (wrangler/miniflare)
- Added .dev.vars to .gitignore

Works in both environments:
- Local dev: uses .dev.vars via miniflare
- Production: uses cloudflare:workers bindings
- Created lib/config/env.ts for centralized env variable access
- Created lib/config/discogs.ts for SDK factory
- Updated all API routes to use createDiscogsSDK()
- Removed duplicate 8-line fallback logic from 5 files
- Added proper TypeScript types for env variables

Benefits:
- DRY: env logic in ONE place
- Type-safe: CloudflareEnv type defines available secrets
- Maintainable: adding secrets = update one file
- Testable: can mock createDiscogsSDK in tests
The user profile endpoint requires OAuth headers, not just the resource URL.
This was causing the callback to fail with HTML error pages.
Bypass SDK OAuth handler in Workers by calling Discogs oauth/request_token
and oauth/access_token directly, constructing a PLAINTEXT OAuth header with
literal '&' in oauth_signature.

Keeps discogs-sdk for normal API calls (identity/profile, collection, search).
Discogs/Workers parsing appears sensitive to raw '&' inside oauth_signature.
Encode the PLAINTEXT signature value so '&' becomes '%26' in the header.
Also keep safe debug flags in request-token failures.
Avoid Authorization header parsing/mutation in Workers by sending OAuth 1.0a
params as application/x-www-form-urlencoded POST body for request_token and
access_token endpoints.
@govi218 govi218 force-pushed the paprika/fix-discogs-deployement branch from f9fae29 to 7a1f77c Compare December 17, 2025 17:33
@netlify
Copy link

netlify bot commented Dec 30, 2025

Deploy Preview for crate-audio ready!

Name Link
🔨 Latest commit 7b987a4
🔍 Latest deploy log https://app.netlify.com/projects/crate-audio/deploys/695c5005b7324a000872f2c5
😎 Deploy Preview https://deploy-preview-131--crate-audio.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@govi218 govi218 force-pushed the paprika/fix-discogs-deployement branch 2 times, most recently from 6b1720d to e19d25d Compare December 30, 2025 07:19
@govi218 govi218 force-pushed the paprika/fix-discogs-deployement branch 3 times, most recently from e86933f to 65c9f7b Compare January 5, 2026 22:14
@govi218 govi218 force-pushed the paprika/fix-discogs-deployement branch from 65c9f7b to c276f33 Compare January 5, 2026 22:16
@govi218 govi218 force-pushed the paprika/fix-discogs-deployement branch from 314c8b3 to 095d096 Compare January 5, 2026 23:44
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