0.1.1 #12

Merged
ric merged 6 commits from 0.1.1 into main 2025-12-04 19:33:42 +00:00
Owner

implement url redirect system. now fully supported and closes #9

implement url redirect system. now fully supported and closes #9
This commit implements a comprehensive redirects system for custom domains
in the pages-server Traefik plugin, allowing users to configure URL redirects
via a .redirects file in their repository.

Features:
- .redirects file support with FROM:TO format (one per line)
- Comment support (lines starting with #)
- /LOAD_REDIRECTS endpoint to activate redirects
- Automatic Traefik redirectregex middleware generation
- Persistent storage in Redis
- Configurable maxRedirects parameter (default: 25)
- Automatic regex character escaping
- Beautiful HTML success/error pages
- Only works on custom domains (not pages domain URLs)

Implementation:
- New redirects.go module with parsing and middleware generation
- Comprehensive test suite in redirects_test.go (>90% coverage)
- Updated Config struct with maxRedirects parameter
- Modified ServeHTTP to handle /LOAD_REDIRECTS endpoint
- Updated README.md with complete redirects documentation
- Updated CHANGELOG.md with feature details

Security:
- Resource exhaustion protection via maxRedirects limit
- Custom domain validation (requires .pages file)
- Only accessible via HTTPS
- Persistent storage prevents repeated repository reads

Testing:
- 12 test cases for parseRedirectsFile
- 6 test cases for escapeRegex
- 6 test cases for generateTraefikRedirectRegexMiddleware
- 3 test cases for formatRedirectList
- All tests passing

Documentation:
- Complete README section on Custom Domain Redirects
- Configuration examples
- Troubleshooting guide
- Security and limitations
- Updated configuration reference table

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Changed middleware format: each redirect now gets its own middleware instance
  (Traefik's redirectregex only supports one redirect per middleware)
- Added updateRouterMiddlewares() to add redirect middlewares to router chain
- Middleware naming: redirects-{domain}-{index} instead of single middleware
- Router middleware chain: redirect middlewares first, then pages-server
- Updated all tests to match new middleware format
- Added fmt import to redirects_test.go

This fixes the issue where redirects were stored in Redis but not applied
by Traefik because they weren't in the router's middleware chain.
Traefik expects 'redirectRegex' (camelCase) not 'redirectregex' (lowercase)
in Redis KV store keys. This was preventing redirects from working.

Changed:
- redirectregex -> redirectRegex in all Redis key paths
- Updated all tests to match camelCase format
- Updated comments to reflect correct format

This fixes the 404 issue where redirects weren't being triggered by Traefik.
The router was only configured for 'websecure' (HTTPS), which meant
redirects only worked on HTTP but not HTTPS.

Now the router handles both entrypoints:
- entryPoints/0 = web (HTTP)
- entryPoints/1 = websecure (HTTPS)

This ensures redirect middlewares work on both HTTP and HTTPS requests.
Two major fixes:
1. Remove regex anchors (^ and $) - Traefik doesn't match with them
2. Use different patterns for absolute vs relative URL redirects:
   - Absolute URLs (https://...): Match full URL with pattern ^https?://[^/]+/path
   - Relative URLs (/path): Match just the path with pattern /path

This fixes the issues where:
- Redirects weren't matching at all (anchor problem)
- Absolute URL redirects were malformed (prepending current domain)

Updated all tests to match new regex patterns.
ric self-assigned this 2025-12-04 19:33:34 +00:00
ric merged commit 4c16cc31d6 into main 2025-12-04 19:33:42 +00:00
ric deleted branch 0.1.1 2025-12-04 19:33:42 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
SquareCows/pages-server!12
No description provided.