Commit 7ac8dfe4 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Add template filter to make nginx addr:port values

Adds a filter for turning (IPAddress, port) tuples into a format
suitable for nginx.

(i.e. "[{addr}]:{port}" if addr is IPv6Address else "{addr}:{port}")
parent fbe85604
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -139,11 +139,19 @@ def parse_annotation(annotation):
def main(argv=None):
	opts = parse_cmdline(argv)

	def nginx_addr_format(input):
		addr, port = input
		if addr.version == 6:
			return f'[{addr}]:{port}'
		else:
			return f'{addr}:{port}'

	# Template engine
	env = jinja2.Environment(
		loader=jinja2.FileSystemLoader('/usr/share/nginx/templates'),
		keep_trailing_newline=True, # It's a line ENDING people! Leave it in.
	)
	env.filters['nginx_addr'] = nginx_addr_format

	# Minimal starting config
	add_core_config(env, opts)
+4 −2
Original line number Diff line number Diff line
server {
	listen {{ external_port|join(':') }} {{ 'udp' if protocol == 'UDP' else '' }};
	proxy_pass {{ internal_port|join(':') }};
	listen {{ external_port|nginx_addr }} {{ 'udp' if protocol == 'UDP' else '' }};
	proxy_pass {{ internal_port|nginx_addr }};
	proxy_protocol {{ 'on' if use_proxy_protocol else 'off' }};
}

# vim: ft=nginx