Skip to content

Conversation

@markphelps
Copy link
Contributor

@markphelps markphelps commented Sep 28, 2025

Summary

This PR configures a Cloudflare Worker to automatically redirect legacy documentation URLs to versioned paths, ensuring backward compatibility for existing links while supporting our new versioned documentation structure (v1 and v2).

Changes

Worker Implementation

  • Simplified redirect logic in worker/src/index.ts to handle four distinct cases:
    1. Root path (/) → redirects to /v2/
    2. Already versioned paths (/v1/*, /v2/*) → proxy through without redirect
    3. Static assets and excluded paths (.css, .js, /api/, etc.) → proxy through without redirect
    4. Unversioned documentation paths → redirect to /v1/* (legacy compatibility)
  • Removed test files that were not being used (test/index.spec.ts, test/env.d.ts, test/tsconfig.json)

CI/CD Pipeline

  • Added GitHub Actions workflow (.github/workflows/worker.yml) to test worker redirects on every PR
    • Deploys worker to a preview environment
    • Runs comprehensive redirect tests to verify all routing rules work correctly
    • Tests include: root redirect, unversioned path redirects, versioned path passthrough, and static asset handling

Configuration

  • Updated wrangler.jsonc to include:
    • Preview environment configuration (docs-preview)
    • Preview URLs enabled for the preview environment
    • Proper environment structure for deployment

Testing

The workflow automatically:

  1. Deploys the worker to a preview environment on Cloudflare
  2. Extracts the preview URL from the deployment
  3. Tests various redirect scenarios against the live preview:
    • Root path redirects to /v2/
    • Unversioned paths redirect to /v1/ equivalents
    • Already versioned paths don't redirect
    • Static assets don't redirect

Requirements

  • Cloudflare API token with appropriate permissions (Workers Scripts Edit, User Details Read, Memberships Read)
  • Secrets configured in GitHub: CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID

Impact

This ensures that:

  • Existing bookmarks and links to documentation continue to work
  • Users on v1 are automatically directed to v1 docs
  • New users landing on the root are directed to the latest v2 docs
  • Static assets and API endpoints are not affected by redirect logic

@markphelps markphelps requested a review from a team as a code owner September 28, 2025 16:00
- Add working-directory to Deploy Worker Preview step
- Specify wrangler.jsonc config file explicitly
- Add preview environment configuration to wrangler.jsonc

This fixes the failing test workflow by ensuring wrangler runs
from the correct directory with the proper configuration.

Signed-off-by: Mark Phelps <[email protected]>
- Enable preview_urls in wrangler configuration
- Remove invalid --out json flag from wrangler deploy
- Extract preview URL from wrangler deploy console output
- Update redirect tests to check for non-redirect status codes
  instead of expecting 200 (since there's no backend to proxy to)

The worker now properly deploys to a preview environment and
tests verify that redirects work as expected.

Signed-off-by: Mark Phelps <[email protected]>
The /dev/tty device doesn't exist in GitHub Actions environment.
Using echo instead to display the output.

Signed-off-by: Mark Phelps <[email protected]>
- Add Node.js setup step
- Install npm dependencies in worker directory
- Use npx to run local wrangler instead of global

This ensures all required dependencies are available for the
worker deployment.

Signed-off-by: Mark Phelps <[email protected]>
Moved preview_urls configuration into the preview environment
section to resolve wrangler warnings about missing environment
and preview_urls configuration.

Signed-off-by: Mark Phelps <[email protected]>
- Add error capture and reporting for wrangler deploy
- Add debug step to verify environment and files
- Don't immediately exit on error to capture output

This will help diagnose why the deployment is failing in CI.

Signed-off-by: Mark Phelps <[email protected]>
Now that the API token permissions are fixed, removing the
debug output and error handling code that was added for
troubleshooting.

Signed-off-by: Mark Phelps <[email protected]>
@markphelps markphelps merged commit eba3698 into main Sep 28, 2025
4 checks passed
@markphelps markphelps deleted the configure-worker-redirects branch September 28, 2025 16:53
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.

1 participant