# Copyright (C) 2026 Doan Luu Duc Tai <doan@luuduct.ai>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

{
    http_port {{HTTP_PORT}}
    https_port {{HTTPS_PORT}}
}

(https_security) {
    header >Strict-Transport-Security "max-age=31536000"
}

https://{{BASE_DOMAIN}}:{{HTTPS_PORT}} {
	import https_security
	handle /.well-known/openpgpkey/* {
		root * /srv
		header Content-Type application/octet-stream
		file_server
	}

	handle {
		redir {{SITE_ORIGIN}}{uri} permanent
	}
}

https://www.{{BASE_DOMAIN}}:{{HTTPS_PORT}} {
	import https_security
	redir {{SITE_ORIGIN}}{uri} permanent
}

https://{{SITE_HOST}}:{{HTTPS_PORT}} {
	import https_security
	root * /srv
	file_server

	redir /git /git/

	handle /cgit* {
		reverse_proxy {{CGIT_UPSTREAM}}
	}

	handle /git/* {
		reverse_proxy {{CGIT_UPSTREAM}}
	}
}

https://{{WKD_HOST}}:{{HTTPS_PORT}} {
	import https_security
	handle /.well-known/openpgpkey/* {
		root * /srv
		header Content-Type application/octet-stream
		file_server
	}
}

https://{{GIT_HOST}}:{{HTTPS_PORT}} {
	import https_security
	redir /{path}.git /{path} permanent

	reverse_proxy {{CGIT_UPSTREAM}}
}

https://{{SEARCH_HOST}}:{{HTTPS_PORT}} {
	import https_security
	reverse_proxy {{SEARXNG_UPSTREAM}}
}

https://www.{{SITE_HOST}}:{{HTTPS_PORT}} {
	import https_security
    redir {{SITE_ORIGIN}}{uri} permanent
}

https://www.{{GIT_HOST}}:{{HTTPS_PORT}} {
	import https_security
    redir {{GIT_ORIGIN}}{uri} permanent
}

https://www.{{SEARCH_HOST}}:{{HTTPS_PORT}} {
	import https_security
    redir {{SEARCH_ORIGIN}}{uri} permanent
}

https://www.{{WKD_HOST}}:{{HTTPS_PORT}} {
    import https_security
    redir {{WKD_ORIGIN}}{uri} permanent
}

https://{{CHAT_HOST}}:{{HTTPS_PORT}} {
    import https_security
    reverse_proxy {{CHAT_UPSTREAM}}
}

https://www.{{CHAT_HOST}}:{{HTTPS_PORT}} {
    import https_security
    redir {{CHAT_PUBLIC_ORIGIN}}{uri} permanent
}
