Files
backend/scripts/websites-agent/patch-nginx-seo.sh
T
Alireza HassaniandCursor ea40ae40d8 Split product sitemap and use Farsi category URLs with ids.
sitemap.xml is now an index of main + products; category loc paths use /products/category/{id}/{nameFaSlug} with a public by-id lookup for storefronts.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-23 00:23:30 +03:30

69 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Insert / update Meshkee SEO proxy locations on an existing storefront nginx site.
# Covers: /sitemap.xml (index), /sitemap-main.xml, /sitemap-products.xml, /robots.txt
set -euo pipefail
HOST="${1:-}"
API_HOST="${MESHKEE_API_HOST:-api.meshkee.com}"
if [[ -z "$HOST" ]]; then
echo "usage: patch-nginx-seo.sh <host>" >&2
exit 1
fi
NGINX_AVAILABLE="/etc/nginx/sites-available/$HOST"
if [[ ! -f "$NGINX_AVAILABLE" ]]; then
echo "missing nginx site for $HOST" >&2
exit 1
fi
proxy_location() {
local path="$1"
local upstream="$2"
cat <<NGINX
location = ${path} {
proxy_pass https://${API_HOST}/api/v1/tenants/${HOST}/${upstream};
proxy_set_header Host ${API_HOST};
proxy_ssl_server_name on;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
add_header Cache-Control "public, max-age=900";
}
NGINX
}
ensure_location() {
local path="$1"
local upstream="$2"
if grep -q "location = ${path}" "$NGINX_AVAILABLE"; then
echo "already present: ${path}"
return 0
fi
local block
block="$(proxy_location "$path" "$upstream")"
local tmp
tmp="$(mktemp)"
awk -v block="$block" '
/location \/ \{/ && !done {
print block
done = 1
}
{ print }
' "$NGINX_AVAILABLE" >"$tmp"
mv "$tmp" "$NGINX_AVAILABLE"
echo "added: ${path}"
}
ensure_location /sitemap.xml sitemap.xml
ensure_location /sitemap-main.xml sitemap-main.xml
ensure_location /sitemap-products.xml sitemap-products.xml
ensure_location /robots.txt robots.txt
nginx -t
systemctl reload nginx
echo "patched nginx SEO locations for $HOST"