char/sorcery

static-files based git repo viewer

git clone https://git.t4t.associates/char/sorcery

Charlotte Somremove --allow-all from ngx script1acdf74

main
1.9 KiB73 linesraw
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  [
23    ngx.serverName(DOMAIN),
24    ...ngx.listen(),
25    ...ngx.http3(),
26    ...ngx.letsEncrypt(DOMAIN),
27  ],
28  "sendfile on",
29  `root ${CACHE}`,
30  ngx("location = /css/style.css", ["try_files $uri @sorcery"]),
31  ngx("location ^~ /js/", ["try_files $uri @sorcery"]),
32  ngx("location ^~ /fonts/", ["try_files $uri @sorcery"]),
33  ngx(`location ~ ^${REPO_ROUTE}/$`, [
34    "try_files ${uri}index.html @sorcery",
35  ]),
36  ngx(`location ~ ^${REPO_ROUTE}/ref/.+/$`, [
37    "try_files ${uri}index.html @sorcery",
38  ]),
39  ngx(`location ~ ^${REPO_ROUTE}/(?:refs|ref/.+/blob/.+)$`, [
40    "try_files $uri @sorcery",
41    ngx("types", []),
42    "default_type text/html",
43  ]),
44  ngx(`location ~ ^${REPO_ROUTE}/gitinfo\\.json$`, [
45    "try_files $uri @sorcery",
46  ]),
47  ngx("location /", [...PROXY]),
48  ngx("location @sorcery", [...PROXY]),
49  ngx("location ~ ^/_sorcery/(.+/ref/.+/blob/.+)$", [
50    "internal",
51    `alias ${CACHE}/$1`,
52    ngx("types", []),
53    "default_type text/html",
54  ]),
55  ngx("location ~ ^/_sorcery/(.+/refs)$", [
56    "internal",
57    `alias ${CACHE}/$1`,
58    ngx("types", []),
59    "default_type text/html",
60  ]),
61  ngx("location /_sorcery/", [
62    "internal",
63    `alias ${CACHE}/`,
64  ]),
65  ngx("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());