Skip to content

Caddy webserver configuration snippets

Serve mkdocs-material static site

gtmx.me {
    # Serve files
    root * /var/www/gtmx.me
    file_server
    # mkdocs-rss-plugin
    rewrite /rss.xml /feed_rss_created.xml
    # Serve mkdocs-material 404 page
    handle_errors {
        @404 expression {http.error.status_code} == 404
        rewrite @404 /404.html
    }
}

Go vanity import for Codeberg-hosted code

# Inspired by https://abhijithota.com/posts/golang-vanity-urls-using-caddy/

(gomod_codeberg) {
    handle /{args[0]} {
        @from_go query go-get=1

        handle @from_go {
            header Content-Type text/html
            respond <<HTML
            <!DOCTYPE html>
            <html>
                <head>
                    <meta
                        name="go-import"
                        content="go.gtmx.me/{args[0]} git https://codeberg.org/gotmax23/{args[0]}"
                    >
                    <meta
                        name="go-source"
                        content="go.gtmx.me/{args[0]} _ https://codeberg.org/gotmax23/{args[0]}/src/branch/main{/dir} https://codeberg.org/gotmax23/{args[0]}/src/branch/main{/dir}/{file}#L{line}"
                    >
                    <title>go get go.gtmx.me/{args[0]}</title>
                </head>
                <body>
                    <p>go get go.gtmx.me/{args[0]}</p>
                </body>
            </html>
            HTML 200
        }

        handle {
            redir https://codeberg.org/gotmax23/{args[0]}
        }
    }
}

go.gtmx.me {
    import gomod_codeberg goorphans
    import gomod_codeberg koschei-filter

    handle {
        redir https://gtmx.me
    }
}