forks/sorcery

git clone https://git.gae.moe/forks/sorcery

Charlotte Somadd user catalog pages94e1677

darwin-flake
2.0 KiB77 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  "expires -1",
30  `root ${CACHE}`,
31  ngx("location = /css/style.css", ["try_files $uri @sorcery"]),
32  ngx("location ^~ /js/", ["try_files $uri @sorcery"]),
33  ngx("location ^~ /fonts/", ["try_files $uri @sorcery"]),
34  ngx(`location ~ ^${REPO_ROUTE}/$`, [
35    "try_files ${uri}index.html @sorcery",
36  ]),
37  ngx(`location ~ ^${REPO_ROUTE}/ref/.+/$`, [
38    "try_files ${uri}index.html @sorcery",
39  ]),
40  ngx(`location ~ ^${REPO_ROUTE}/(?:refs|ref/.+/blob/.+)$`, [
41    "try_files $uri @sorcery",
42    ngx("types", []),
43    "default_type text/html",
44  ]),
45  ngx(`location ~ ^${REPO_ROUTE}/gitinfo\\.json$`, [
46    "try_files $uri @sorcery",
47  ]),
48  ngx("location = /", [...PROXY]),
49  ngx("location ~ ^/[^/]+/$", [...PROXY]),
50  ngx("location /", [...PROXY, "expires off"]),
51  ngx("location @sorcery", [...PROXY, "expires off"]),
52  ngx("location ~ ^/_sorcery/(.+/ref/.+/blob/.+)$", [
53    "internal",
54    `alias ${CACHE}/$1`,
55    ngx("types", []),
56    "default_type text/html",
57  ]),
58  ngx("location ~ ^/_sorcery/(.+/refs)$", [
59    "internal",
60    `alias ${CACHE}/$1`,
61    ngx("types", []),
62    "default_type text/html",
63  ]),
64  ngx("location /_sorcery/", [
65    "internal",
66    `alias ${CACHE}/`,
67  ]),
68  ngx("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());