"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Landry Breuil <landry@openbsd.org>
Subject:
nginx rewrites to migrate from cgit to gotwebd
To:
gameoftrees@openbsd.org
Date:
Tue, 28 May 2024 09:37:20 +0200

Download raw body.

Thread
hi,

currently migrating services, i'd like to get rid of cgit because slowcgi, but
the urls are handy. i've come up with the following that isn't perfect but is a
start, and works for some cgit-like urls.

map $arg_h $branch {
        '' 'HEAD';
        ~. $arg_h;
}

map $arg_id $commit {
        '' '';
        ~. &commit=$arg_id;
}

location /c/ {
        rewrite_log on;
        error_log /tmp/ngx_rewrite.log notice;
        rewrite /c/(?<repo>.*)/diff/$                            /gotwebd/?path=$repo$commit&headref=$branch&action=diff? last;
        rewrite /c/(?<repo>.*)/diff/(?<file>.*)                  /gotwebd/?path=$repo$commit&headref=$branch&action=diff&file=$file&folder=? last;
        rewrite /c/(?<repo>.*)/patch/                            /gotwebd/?path=$repo$commit&action=patch? last;
        rewrite /c/(?<repo>.*)/refs/                             /gotwebd/?path=$repo$commit&headref=$branch&action=briefs? last;
        rewrite /c/(?<repo>.*)/plain/(?<file>.*)                 /gotwebd/?path=$repo$commit&action=blobraw&file=$file&folder=? last;
        rewrite /c/(?<repo>.*)/tree/$                            /gotwebd/?path=$repo$commit&action=tree? last;
        rewrite /c/(?<repo>.*)/tree/(?<folder>.*)/(?<file>[!/]*) /gotwebd/?path=$repo$commit&action=blob&folder=$folder&file=$file? last;
        rewrite /c/(?<repo>.*)/tree/(?<file>[!/]*)               /gotwebd/?path=$repo$commit&action=blob&file=$file&folder=? last;
        rewrite /c/(?<repo>.*)/commit/                           /gotwebd/?path=$repo$commit&headref=$branch&action=diff? last;
        rewrite /c/(?<repo>.*)/log/                              /gotwebd/?path=$repo$commit&headref=$branch&action=commits? last;
        rewrite /c/(?<repo>.*)/                                  /gotwebd/?path=$repo$commit&headref=$branch&action=summary? last;
}

the /c/ is for testing rewrites, the final idea is to have this location block
at the root to replace cgit.

one thing i've noticed is that gotwebd complains with invalid query string when
the commit arg is unset, couldn't we assume it's the HEAD commit in that case?

Landry