forks/sorcery
git clone https://git.gae.moe/forks/sorcery
94e1677
darwin-flake
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"expires -1" , 30`root ${ CACHE } ` , 31ngx ( "location = /css/style.css" , [ "try_files $uri @sorcery" ]), 32ngx ( "location ^~ /js/" , [ "try_files $uri @sorcery" ]), 33ngx ( "location ^~ /fonts/" , [ "try_files $uri @sorcery" ]), 34ngx ( `location ~ ^ ${ REPO_ROUTE } /$` , [ 35"try_files ${uri}index.html @sorcery" , 36]), 37ngx ( `location ~ ^ ${ REPO_ROUTE } /ref/.+/$` , [ 38"try_files ${uri}index.html @sorcery" , 39]), 40ngx ( `location ~ ^ ${ REPO_ROUTE } /(?:refs|ref/.+/blob/.+)$` , [ 41"try_files $uri @sorcery" , 42ngx ( "types" , []), 43"default_type text/html" , 44]), 45ngx ( `location ~ ^ ${ REPO_ROUTE } /gitinfo\\.json$` , [ 46"try_files $uri @sorcery" , 47]), 48ngx ( "location = /" , [ ...PROXY ]), 49ngx ( "location ~ ^/[^/]+/$" , [ ...PROXY ]), 50ngx ( "location /" , [ ...PROXY , "expires off" ]), 51ngx ( "location @sorcery" , [ ...PROXY , "expires off" ]), 52ngx ( "location ~ ^/_sorcery/(.+/ref/.+/blob/.+)$" , [ 53"internal" , 54`alias ${ CACHE } /$1` , 55ngx ( "types" , []), 56"default_type text/html" , 57]), 58ngx ( "location ~ ^/_sorcery/(.+/refs)$" , [ 59"internal" , 60`alias ${ CACHE } /$1` , 61ngx ( "types" , []), 62"default_type text/html" , 63]), 64ngx ( "location /_sorcery/" , [ 65"internal" , 66`alias ${ CACHE } /` , 67]), 68ngx ( "location /_sorcery-git/" , [ 69"internal" , 70`alias ${ REPOSITORIES } /` , 71"expires off" , 72]), 73]); 74 75export const path = "sorcery.conf" ; 76 77if ( import . meta. main ) console . log ( config . build ());