# Full androidcast vhost for Alpine BE — listen 80 only.
# FE (apps.f0xx.org) proxies here: proxy_pass http://artc0.intra.raptor.org:80;
# Port 8089 is a different service (e.g. Janus) — not this vhost.

server {
	listen 80;

	# OTA v0 static tree — devices fetch https://apps.f0xx.org/v0/ota/channel/stable.json
	# Populate: builder auto_deploy, or rsync out/ota/v0/ → .../ota-artifacts/v0/
	location ^~ /v0/ota/ {
		alias /var/www/localhost/htdocs/apps/app/androidcast_project/ota-artifacts/v0/ota/;
		add_header Cache-Control "public, max-age=60";
	}

	location = /app/androidcast_project {
		return 301 /app/androidcast_project/;
	}

	location = /app/androidcast_project/index.php {
		include fastcgi_params;
		fastcgi_pass unix:/run/php-fpm.socket;
		fastcgi_param SCRIPT_FILENAME /var/www/localhost/htdocs/apps/app/androidcast_project/index.php;
		fastcgi_param SCRIPT_NAME /app/androidcast_project/index.php;
	}

	location = /app/androidcast_project/ {
		rewrite ^ /app/androidcast_project/index.php last;
	}

	location /app/androidcast_project/ {
		alias /var/www/localhost/htdocs/apps/app/androidcast_project/;
		index index.php index.html;
		try_files $uri $uri/ =404;
	}

	location = /app/androidcast_project/crashes {
		return 301 /app/androidcast_project/crashes/;
	}

	location = /app/androidcast_project/graphs {
		return 301 /app/androidcast_project/graphs/;
	}

	location ^~ /app/androidcast_project/crashes/assets/ {
		alias /var/www/localhost/htdocs/apps/app/androidcast_project/android_cast/examples/crash_reporter/backend/public/assets/;
	}

	location ^~ /app/androidcast_project/graphs/assets/ {
		alias /var/www/localhost/htdocs/apps/app/androidcast_project/android_cast/examples/crash_reporter/backend/public/assets/;
	}

	location = /app/androidcast_project/crashes/api/upload.php {
		include fastcgi_params;
		fastcgi_pass unix:/run/php-fpm.socket;
		fastcgi_param SCRIPT_FILENAME /var/www/localhost/htdocs/apps/app/androidcast_project/android_cast/examples/crash_reporter/backend/public/api/upload.php;
		fastcgi_param SCRIPT_NAME /app/androidcast_project/crashes/api/upload.php;
		fastcgi_param REQUEST_URI $request_uri;
		client_max_body_size 4m;
	}

	location ^~ /app/androidcast_project/crashes/ {
		include fastcgi_params;
		fastcgi_pass unix:/run/php-fpm.socket;
		fastcgi_param SCRIPT_FILENAME /var/www/localhost/htdocs/apps/app/androidcast_project/android_cast/examples/crash_reporter/backend/public/index.php;
		fastcgi_param SCRIPT_NAME /app/androidcast_project/crashes/index.php;
		fastcgi_param REQUEST_URI $request_uri;
		client_max_body_size 4m;
	}

	location = /app/androidcast_project/graphs/api/graphs.php {
		include fastcgi_params;
		fastcgi_pass unix:/run/php-fpm.socket;
		fastcgi_param SCRIPT_FILENAME /var/www/localhost/htdocs/apps/app/androidcast_project/android_cast/examples/crash_reporter/backend/public/api/graphs.php;
		fastcgi_param SCRIPT_NAME /app/androidcast_project/graphs/api/graphs.php;
		fastcgi_param REQUEST_URI $request_uri;
	}

	location = /app/androidcast_project/graphs/api/graph_upload.php {
		include fastcgi_params;
		fastcgi_pass unix:/run/php-fpm.socket;
		fastcgi_param SCRIPT_FILENAME /var/www/localhost/htdocs/apps/app/androidcast_project/android_cast/examples/crash_reporter/backend/public/api/graph_upload.php;
		fastcgi_param SCRIPT_NAME /app/androidcast_project/graphs/api/graph_upload.php;
		fastcgi_param REQUEST_URI $request_uri;
		client_max_body_size 4m;
	}

	location ^~ /app/androidcast_project/graphs/ {
		include fastcgi_params;
		fastcgi_pass unix:/run/php-fpm.socket;
		fastcgi_param SCRIPT_FILENAME /var/www/localhost/htdocs/apps/app/androidcast_project/android_cast/examples/crash_reporter/backend/public/index.php;
		fastcgi_param SCRIPT_NAME /app/androidcast_project/graphs/index.php;
		fastcgi_param REQUEST_URI $request_uri;
		client_max_body_size 4m;
	}

	location = /app/androidcast_project/build {
		return 301 /app/androidcast_project/build/;
	}

	location ^~ /app/androidcast_project/build/assets/ {
		alias /var/www/localhost/htdocs/apps/app/androidcast_project/android_cast/examples/build_console/backend/public/assets/;
	}

	location ^~ /app/androidcast_project/build/ {
		include fastcgi_params;
		fastcgi_pass unix:/run/php-fpm.socket;
		fastcgi_param SCRIPT_FILENAME /var/www/localhost/htdocs/apps/app/androidcast_project/android_cast/examples/build_console/backend/public/index.php;
		fastcgi_param SCRIPT_NAME /app/androidcast_project/build/index.php;
		fastcgi_param REQUEST_URI $request_uri;
		client_max_body_size 512m;
		fastcgi_read_timeout 1800s;
	}

	location ~ \.php$ {
		include /etc/nginx/fastcgi.conf;
		fastcgi_pass unix:/run/php-fpm.socket;
	}
}
