char/sorcery
static-files based git repo viewer
git clone https://git.t4t.associates/char/sorcery
1acdf74
main
1#!/usr/bin/env -S deno run 2 3import ngx from "jsr:@char/ngx@0.2" ; 4 5const DOMAIN = "my-cool-git.example" ; 6const SOCKET = "/run/sorcery/sock" ; 7const CACHE = "/var/cache/sorcery" ; 8const REPOSITORIES = "/home/git/public" ; 9 10const PROXY = [ 11`proxy_pass http://unix: ${ SOCKET } ` , 12"proxy_http_version 1.1" , 13"proxy_set_header Host $host" , 14"proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for" , 15"proxy_set_header X-Forwarded-Proto $scheme" , 16"client_max_body_size 64m" , 17]; 18 19const REPO_ROUTE = "/[^/]+/[^/]+" ; 20 21export const config = ngx ( "server" , [ 22[ 23ngx . serverName ( DOMAIN ), 24 ...ngx . listen (), 25 ...ngx . http3 (), 26 ...ngx . letsEncrypt ( DOMAIN ), 27], 28"sendfile on" , 29`root ${ CACHE } ` , 30ngx ( "location = /css/style.css" , [ "try_files $uri @sorcery" ]), 31ngx ( "location ^~ /js/" , [ "try_files $uri @sorcery" ]), 32ngx ( "location ^~ /fonts/" , [ "try_files $uri @sorcery" ]), 33ngx ( `location ~ ^ ${ REPO_ROUTE } /$` , [ 34"try_files ${uri}index.html @sorcery" , 35]), 36ngx ( `location ~ ^ ${ REPO_ROUTE } /ref/.+/$` , [ 37"try_files ${uri}index.html @sorcery" , 38]), 39ngx ( `location ~ ^ ${ REPO_ROUTE } /(?:refs|ref/.+/blob/.+)$` , [ 40"try_files $uri @sorcery" , 41ngx ( "types" , []), 42"default_type text/html" , 43]), 44ngx ( `location ~ ^ ${ REPO_ROUTE } /gitinfo\\.json$` , [ 45"try_files $uri @sorcery" , 46]), 47ngx ( "location /" , [ ...PROXY ]), 48ngx ( "location @sorcery" , [ ...PROXY ]), 49ngx ( "location ~ ^/_sorcery/(.+/ref/.+/blob/.+)$" , [ 50"internal" , 51`alias ${ CACHE } /$1` , 52ngx ( "types" , []), 53"default_type text/html" , 54]), 55ngx ( "location ~ ^/_sorcery/(.+/refs)$" , [ 56"internal" , 57`alias ${ CACHE } /$1` , 58ngx ( "types" , []), 59"default_type text/html" , 60]), 61ngx ( "location /_sorcery/" , [ 62"internal" , 63`alias ${ CACHE } /` , 64]), 65ngx ( "location /_sorcery-git/" , [ 66"internal" , 67`alias ${ REPOSITORIES } /` , 68]), 69]); 70 71export const path = "sorcery.conf" ; 72 73if ( import . meta. main ) console . log ( config . build ());