#!/usr/bin/env -S deno run import ngx from "jsr:@char/ngx@0.2"; const DOMAIN = "my-cool-git.example"; const SOCKET = "/run/sorcery/sock"; const CACHE = "/var/cache/sorcery"; const REPOSITORIES = "/home/git/public"; const PROXY = [ `proxy_pass http://unix:${SOCKET}`, "proxy_http_version 1.1", "proxy_set_header Host $host", "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for", "proxy_set_header X-Forwarded-Proto $scheme", "client_max_body_size 64m", ]; const REPO_ROUTE = "/[^/]+/[^/]+"; export const config = ngx("server", [ [ ngx.serverName(DOMAIN), ...ngx.listen(), ...ngx.http3(), ...ngx.letsEncrypt(DOMAIN), ], "sendfile on", `root ${CACHE}`, ngx("location = /css/style.css", ["try_files $uri @sorcery"]), ngx("location ^~ /js/", ["try_files $uri @sorcery"]), ngx("location ^~ /fonts/", ["try_files $uri @sorcery"]), ngx(`location ~ ^${REPO_ROUTE}/$`, [ "try_files ${uri}index.html @sorcery", ]), ngx(`location ~ ^${REPO_ROUTE}/ref/.+/$`, [ "try_files ${uri}index.html @sorcery", ]), ngx(`location ~ ^${REPO_ROUTE}/(?:refs|ref/.+/blob/.+)$`, [ "try_files $uri @sorcery", ngx("types", []), "default_type text/html", ]), ngx(`location ~ ^${REPO_ROUTE}/gitinfo\\.json$`, [ "try_files $uri @sorcery", ]), ngx("location /", [...PROXY]), ngx("location @sorcery", [...PROXY]), ngx("location ~ ^/_sorcery/(.+/ref/.+/blob/.+)$", [ "internal", `alias ${CACHE}/$1`, ngx("types", []), "default_type text/html", ]), ngx("location ~ ^/_sorcery/(.+/refs)$", [ "internal", `alias ${CACHE}/$1`, ngx("types", []), "default_type text/html", ]), ngx("location /_sorcery/", [ "internal", `alias ${CACHE}/`, ]), ngx("location /_sorcery-git/", [ "internal", `alias ${REPOSITORIES}/`, ]), ]); export const path = "sorcery.conf"; if (import.meta.main) console.log(config.build());