~ knotless Search/
↑↓ move↵ open⇧↵ all results

zat.dev/stream

jetstream v2 in zig · mirror of https://tangled.org/zat.dev/stream

0
0
116 lines · 2.9 KB Raw History
grafana.stream.waow.tech {
	reverse_proxy grafana:3000
}

stream.89-167-122-160.sslip.io, stream.waow.tech, jetstream.waow.tech {
	# edge admission control (mholt/caddy-ratelimit, sliding window).
	# per-IP keys grouped by /24 (v4) and /56 (v6) so address cycling
	# inside one allocation shares a bucket. limits bound REQUEST rates
	# only; concurrent-subscriber and cold-replay caps live in-process
	# (the proxy cannot see what a connection costs the archive).
	rate_limit {
		# websocket connect attempts: a healthy consumer reconnects rarely;
		# 30 per 5m per /24 tolerates flapping without permitting a spray
		zone ws_connect {
			match {
				header Connection *Upgrade*
			}
			key {remote_host}
			events 30
			window 5m
			ipv4_prefix 24
			ipv6_prefix 56
		}
		# keyed archive traffic: a 32 MB/s consumer runs ~150 getBlock/s
		# (~214 KB avg block), so the ceiling must sit well above that;
		# byte-rate fairness is the key ring's job, this only stops
		# request-rate floods with a forged bearer header
		zone xrpc_keyed {
			match {
				path /xrpc/*
				header Authorization Bearer*
			}
			key {remote_host}
			events 15000
			window 1m
		}
		# everything anonymous: static site, /metrics, /status, and
		# unauthenticated xrpc probes (401 spray) share one modest bucket
		zone anon_http {
			match {
				not header Connection *Upgrade*
				not header Authorization Bearer*
			}
			key {remote_host}
			events 240
			window 1m
			ipv4_prefix 24
			ipv6_prefix 56
		}
	}

	# Public playground; static assets and a deploy-time summary snapshot.
	root * /srv/site
	redir /strata /strata/ permanent
	redir /_strata-preview /strata/ permanent
	handle_path /_strata-preview/* {
		redir * /strata{uri} permanent
	}
	handle /strata/* {
		# Preserve summary API URLs for clients of the former UI.
		@strata_api path /strata/api /strata/api/*
		handle @strata_api {
			uri strip_prefix /strata
			reverse_proxy https://strata.zat.dev {
				header_up Host strata.zat.dev
			}
		}
		handle /strata/assets/* {
			header Cache-Control "public, max-age=31536000, immutable"
			file_server {
				precompressed gzip
			}
		}
		handle {
			header Cache-Control "public, max-age=60, stale-while-revalidate=86400, stale-if-error=604800"
			file_server {
				precompressed gzip
			}
		}
	}
	@home path / /index.html
	handle @home {
		header Cache-Control "no-cache"
		templates {
			mime text/html
		}
		file_server
	}
	@static path /llms.txt /favicon.svg /ambient.js /brand.css /river.js
	handle @static {
		file_server
	}
	handle /stats {
		header Cache-Control "no-cache"
		rewrite * /stats.html
		file_server
	}
	@statushtml {
		path /status
		header Accept *text/html*
	}
	handle @statushtml {
		rewrite * /statuspage.html
		file_server
	}
	handle /metrics {
		reverse_proxy stream:6060
	}
	handle {
		# subscriber websockets survive config reloads: without this, any
		# caddy reload severs every proxied stream and consumers fail over
		reverse_proxy stream:8080 {
			stream_close_delay 24h
		}
	}
}