Compare commits

..

View file

@ -12,26 +12,18 @@ let
# ROOT_URL forgejo advertises in clone links + outbound URLs. When # ROOT_URL forgejo advertises in clone links + outbound URLs. When
# served behind the gateway, `cfg.domain` doubles as both the # served behind the gateway, `cfg.domain` doubles as both the
# forgejo `DOMAIN` setting AND the gateway vhost server-name, so # forgejo `DOMAIN` setting AND the gateway vhost server-name, so
# ROOT_URL just uses it directly (dropping the port suffix on the # ROOT_URL just uses it directly (drops the port suffix when the
# canonical port for the scheme — 80 for http, 443 for https). The # gateway is on the canonical port 80). When direct (gateway off
# scheme + port follow what the gateway actually serves: `https` when # or `behindGateway = false`), keep the host:port shape so direct
# the gateway terminates TLS (a self-signed cert or an external # browser access on `:httpPort` still produces correct links.
# `tls.certDir`), `http` otherwise — advertising `http://` for a TLS # Operators can override via `cfg.rootUrl` for TLS / non-default
# gateway produces broken clone links + mixed-content redirects. # gateway ports / bespoke shapes.
# When direct (gateway off or `behindGateway = false`), keep the
# host:httpPort shape so direct browser access still produces correct
# links. Operators can still override via `cfg.rootUrl` for bespoke
# shapes.
gatewayTls = gatewayCfg.selfSignedTls || gatewayCfg.tls.certDir != null;
defaultRootUrl = defaultRootUrl =
if cfg.behindGateway then if cfg.behindGateway then
let let
scheme = if gatewayTls then "https" else "http"; portSuffix = if gatewayCfg.port == 80 then "" else ":${toString gatewayCfg.port}";
port = if gatewayTls then gatewayCfg.httpsPort else gatewayCfg.port;
canonicalPort = if gatewayTls then 443 else 80;
portSuffix = if port == canonicalPort then "" else ":${toString port}";
in in
"${scheme}://${cfg.domain}${portSuffix}/" "http://${cfg.domain}${portSuffix}/"
else else
"http://${cfg.domain}:${toString cfg.httpPort}/"; "http://${cfg.domain}:${toString cfg.httpPort}/";
effectiveRootUrl = if cfg.rootUrl != null then cfg.rootUrl else defaultRootUrl; effectiveRootUrl = if cfg.rootUrl != null then cfg.rootUrl else defaultRootUrl;
@ -155,19 +147,16 @@ in
description = '' description = ''
Override the auto-derived forgejo `ROOT_URL`. When `null` Override the auto-derived forgejo `ROOT_URL`. When `null`
(default), `ROOT_URL` is derived from `cfg.domain` + gateway (default), `ROOT_URL` is derived from `cfg.domain` + gateway
state, including the scheme: state:
- `behindGateway = true` `https://''${cfg.domain}/` when the - `behindGateway = true` `http://''${cfg.domain}/` (uses
gateway terminates TLS (`gateway.selfSignedTls = true` or `services.hyperhive.gateway.port` when non-80)
`gateway.tls.certDir` set), otherwise `http://''${cfg.domain}/`.
A non-canonical gateway port (`gateway.port` for http,
`gateway.httpsPort` for https) is appended as `:<port>`.
- `behindGateway = false` `http://''${cfg.domain}:''${cfg.httpPort}/` - `behindGateway = false` `http://''${cfg.domain}:''${cfg.httpPort}/`
The TLS scheme is derived automatically now, so you only need to Set this to a fully-qualified URL when running behind TLS
set this for a genuinely bespoke shape (e.g. an external reverse termination (`https://...`), a non-default gateway port, or
proxy on a different host/path). Must end with `/` per forgejo's a bespoke shape. Must end with `/` per forgejo's `ROOT_URL`
`ROOT_URL` contract. contract.
''; '';
}; };