Investigate serving branch versions #13
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
SquareCows/pages-server#13
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Investigate how we can serve sites from branches in git to allow for stage etc.
Based on my exploration, here's the current state and possible approaches for serving different branches:
Current State
The plugin only serves from the repository's default branch (main/master). While it fetches the default branch name from the
Forgejo API, it doesn't actually use it - all file requests go to the default branch implicitly.
Design Options for Multi-Branch Support
Option 1: URL-Based Branch Selection
Add branch to the URL path, similar to how Netlify/Vercel handle branch deploys:
URL patterns:
Pros:
Cons:
Option 2: Configuration-Based (.pages file)
Add a branch: field to the .pages configuration:
enabled: true
branch: develop
custom_domain: example.com
Pros:
Cons:
Option 3: Hybrid Approach
Pros:
Cons:
Implementation Changes Needed
All options require modifying:
Query based approach:
The Problem
If you visit:
https://username.pages.domain/repo/?branch=develop
And the page contains internal links like:
About
Contact
Blog
Clicking any of those links would drop the ?branch=develop parameter and fall back to the default branch. Users would
constantly jump between branches - terrible UX!
Solutions
Option 1: Cookie-Based Persistence ⭐ (Best for browsers)
When the plugin sees ?branch=develop:
User flow:
Visit: https://username.pages.domain/repo/?branch=develop
→ Cookie set: pages-branch=develop
Click link:
→ Navigates to: /about.html
→ Cookie still says: develop
→ Serves from develop branch ✓
Want to switch back? Visit: ?branch=main
→ Cookie updated to main
Pros:
Cons:
Option 2: Path-Based Routing
https://username.pages.domain/repo/~develop/index.html
https://username.pages.domain/repo/~develop/about.html
Pros:
Cons:
Option 3: Hybrid (Cookie + Query + Header)
Priority: ?branch= > X-Pages-Branch > Cookie > .pages config > default
This gives the best of all worlds!