forgejopages

package module
v0.0.0-...-4cf9b45 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2025 License: MIT Imports: 27 Imported by: 0

README

Caddy Forgejo Pages

Development Status Not Production Ready Version

⚠️ DEVELOPMENT WARNING ⚠️
This project is currently in active development and is NOT ready for production use.
Features may be incomplete, unstable, or subject to breaking changes.
Use at your own risk and avoid deploying in production environments.


A Caddy module that enables automatic deployment of static sites from Forgejo/Gitea repositories via webhooks, similar to GitHub Pages or GitLab Pages.

⚠️ Current Status

This is an early-stage development project with the following limitations:

  • 🚧 Alpha software - Core functionality still being implemented
  • 🐛 Known bugs - Several features may not work as expected
  • 🔄 Breaking changes - API and configuration may change without notice
  • 📚 Limited documentation - Setup guides may be incomplete
  • 🧪 Testing required - Minimal real-world testing completed
  • 🔒 Security review needed - Not audited for production security

DO NOT USE IN PRODUCTION until we reach a stable v1.0.0 release.

Features

  • 🔄 Automatic Deployment: Deploy sites automatically via webhooks
  • 🌐 Custom Domains: Support for custom domains via .domain files
  • 🚀 Dynamic Configuration: Updates Caddy configuration without restarts
  • 📦 Lazy Loading: Repositories cloned on first access
  • 🔒 Secure: HMAC webhook signature validation
  • 📧 Notifications: Email notifications for deployment errors
  • 🧹 Auto Cleanup: Automatic cleanup of unused sites

URL Patterns

  • https://username.pages.example.com → Default repository, main branch
  • https://username.pages.example.com/repository → Specific repository, main branch
  • https://username.pages.example.com/repository/@branch → Specific repository and branch
  • https://custom.com → Custom domain (if .domain file present)

Installation

Using xcaddy
xcaddy build --with codeberg.org/YOURUSERNAME/caddy-forgejo-pages
Manual Build
go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
xcaddy build --with codeberg.org/YOURUSERNAME/caddy-forgejo-pages

Configuration

Caddyfile
{
    forgejo_pages {
        base_domain "pages.example.com"
        storage_path "/var/caddy-pages"
        cleanup_days 30
        notification_email "admin@example.com"
        smtp_server "smtp.example.com:587"
        smtp_username "notifications@example.com"
        smtp_password "your-smtp-password"
        webhook_secret "your-webhook-secret"
    }
}

*.pages.example.com {
    forgejo_pages
    respond "Site not found" 404
}

example.com {
    forgejo_pages
    file_server
}
JSON Configuration
{
    "apps": {
        "forgejo_pages": {
            "base_domain": "pages.example.com",
            "storage_path": "/var/caddy-pages",
            "cleanup_days": 30,
            "notification_email": "admin@example.com",
            "smtp_server": "smtp.example.com:587",
            "smtp_username": "notifications@example.com",
            "smtp_password": "your-smtp-password",
            "webhook_secret": "your-webhook-secret"
        }
    }
}

Usage

  1. Setup Repository: Create a repository with static files
  2. Custom Domain (optional): Add a .domain file with your custom domain
  3. Configure Webhook: Add webhook URL: https://example.com/.well-known/forgejo-pages/webhook
  4. Push Changes: Push to trigger automatic deployment

Configuration Options

Option Description Default
base_domain Base domain for pages Required
storage_path Directory for storing repositories /var/caddy-pages
cleanup_days Days before cleaning unused sites 30
notification_email Email for error notifications Optional
smtp_server SMTP server for notifications Optional
smtp_username SMTP username Optional
smtp_password SMTP password Optional
webhook_secret Secret for webhook validation Optional

Repository Structure

Your repository should contain:

  • index.html - Main page
  • .domain - (Optional) Custom domain on first line
  • Static assets (CSS, JS, images, etc.)

License

MIT License - see LICENSE file for details.

Contributing

Pull requests welcome! Please see CONTRIBUTING.md for guidelines.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeployedSite

type DeployedSite struct {
	Username     string
	Repository   string
	Branch       string
	BaseDomain   string
	CustomDomain string
	Path         string
	LastAccess   time.Time
	BackupPath   string
	CloneURL     string
}

DeployedSite rappresenta un sito deployato

type ForgejoPages

type ForgejoPages struct {
	// contains filtered or unexported fields
}

ForgejoPages è il middleware handler

func (*ForgejoPages) CaddyModule

func (*ForgejoPages) CaddyModule() caddy.ModuleInfo

CaddyModule ritorna le informazioni del modulo handler

func (*ForgejoPages) Provision

func (f *ForgejoPages) Provision(ctx caddy.Context) error

Provision configura il middleware

func (*ForgejoPages) ServeHTTP

func (f *ForgejoPages) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error

ServeHTTP gestisce le richieste HTTP

type ForgejoPagesApp

type ForgejoPagesApp struct {
	BaseDomain        string `json:"base_domain"`
	StoragePath       string `json:"storage_path,omitempty"`
	CleanupDays       int    `json:"cleanup_days,omitempty"`
	NotificationEmail string `json:"notification_email,omitempty"`
	SMTPServer        string `json:"smtp_server,omitempty"`
	SMTPUsername      string `json:"smtp_username,omitempty"`
	SMTPPassword      string `json:"smtp_password,omitempty"`
	WebhookSecret     string `json:"webhook_secret,omitempty"`
	GracePeriod       string `json:"domain_transition_grace,omitempty"`
	// contains filtered or unexported fields
}

ForgejoPagesApp implementa caddy.App per la gestione globale

func (*ForgejoPagesApp) CaddyModule

func (*ForgejoPagesApp) CaddyModule() caddy.ModuleInfo

CaddyModule ritorna le informazioni del modulo app

func (*ForgejoPagesApp) Provision

func (f *ForgejoPagesApp) Provision(ctx caddy.Context) error

Provision configura l'app

func (*ForgejoPagesApp) Start

func (f *ForgejoPagesApp) Start() error

Start avvia l'app

func (*ForgejoPagesApp) Stop

func (f *ForgejoPagesApp) Stop() error

Stop ferma l'app

func (*ForgejoPagesApp) Validate

func (f *ForgejoPagesApp) Validate() error

Validate verifica la configurazione dell'app

type RouteInfo

type RouteInfo struct {
	Username   string
	Repository string
	Branch     string
	Path       string
}

RouteInfo contiene informazioni parsed da una richiesta

type WebhookPayload

type WebhookPayload struct {
	Ref        string `json:"ref"`
	Repository struct {
		ID       int    `json:"id"`
		Name     string `json:"name"`
		FullName string `json:"full_name"`
		CloneURL string `json:"clone_url"`
		Owner    struct {
			Login    string `json:"login"`
			Username string `json:"username"`
		} `json:"owner"`
		DefaultBranch string `json:"default_branch"`
	} `json:"repository"`
}

WebhookPayload rappresenta il payload del webhook di Forgejo

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL